本文整理汇总了C#中Nancy.Hosting.Self.NancyHost.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# NancyHost.Dispose方法的具体用法?C# NancyHost.Dispose怎么用?C# NancyHost.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Hosting.Self.NancyHost
的用法示例。
在下文中一共展示了NancyHost.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var config = new HostConfiguration();
//config.UrlReservations.CreateAutomatically = true;
config.RewriteLocalhost = false;
var bootstrapper = new Bootstrapper();
host = new NancyHost(bootstrapper, config, baseUri);
for (int i = 0; ; i++)
{
try
{
host.Start();
break;
}
catch (HttpListenerException ex)
{
// Error 183 happens when the HttpListener fails to listen on the provided Uri
if (ex.ErrorCode != 183 || i >= 10) throw;
// Close the already running instance
try
{
new WebClient().DownloadString(new Uri(baseUri, "/Close"));
System.Threading.Thread.Sleep(40); // Feels like enough :P
}
catch { }
}
}
Console.WriteLine("Your application is running on: " + baseUri);
Console.WriteLine("You can type relative URIs to test routes, or enter an empty line to exit");
var engine = bootstrapper.GetEngine();
while (true)
{
var line = Console.ReadLine();
if (line == "") break;
var req = new Request("GET", new Url(baseUri + line));
var res = engine.HandleRequest(req).Response;
Console.WriteLine("Response Code: " + res.StatusCode);
res.Contents(Console.OpenStandardOutput());
Console.WriteLine();
}
ProcModule.KillAllProcs();
host.Dispose();
}
示例2: Main
public static void Main(string[] args)
{
Models.Benchmark.Initialize ();
Models.Configuration.Initialize ();
Models.Counter.Initialize ();
Models.Device.Initialize ();
Models.Project.Initialize ();
Models.Recipe.Initialize ();
Models.Revision.Initialize ();
Models.Run.Initialize ();
Models.Sample.Initialize ();
var nancyHost = new NancyHost (new Uri ("http://127.0.0.1:8080/"), new Uri ("http://10.1.12.185:8080/"));
nancyHost.Start ();
StaticConfiguration.DisableErrorTraces = false;
StaticConfiguration.Caching.EnableRuntimeViewUpdates = true;
Console.WriteLine ("Nancy now listening on http://127.0.0.1:8080/. Press key to stop");
while (true) {
if (Console.ReadKey ().Key == ConsoleKey.Enter) {
break;
}
Thread.Sleep (100);
}
nancyHost.Stop ();
nancyHost.Dispose ();
Console.WriteLine ("The End;");
}