本文整理汇总了C#中HttpListener.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.Abort方法的具体用法?C# HttpListener.Abort怎么用?C# HttpListener.Abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpListener
的用法示例。
在下文中一共展示了HttpListener.Abort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
uriBaseAddress = args[0];
if (!uriBaseAddress.EndsWith("/"))
uriBaseAddress += "/";
useV2Host = false;
if (args.Length > 1)
useV2Host = bool.Parse(args[1]);
string waitHandleName = null;
if (args.Length > 2)
waitHandleName = args[2];
serviceType = Assembly.GetExecutingAssembly()
.GetTypes()
.Single(t => !t.IsAbstract
&& typeof(Microsoft.OData.Service.IRequestHandler).IsAssignableFrom(t));
HttpListener listener = new HttpListener();
try
{
listener.Prefixes.Add(uriBaseAddress);
listener.Start();
listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
}
catch (Exception e)
{
Console.WriteLine("An exception occurred:");
Console.WriteLine(e.ToString());
listener.Abort();
Console.ReadLine();
}
// both of the following cases will block, so there is no need for a loop
if (waitHandleName == "Debug" || string.IsNullOrEmpty(waitHandleName))
{
Console.WriteLine("Running in Debug mode, please press any key to exit");
// blocks until key pressed
Console.Read();
}
else
{
// if the wait handle name was specified on the command line, then the test infrastructure
// must have created one for us to wait on
// we do this instead of blocking on the command line because it has proven to be more robust
// and much easier to shut down the service when disposing the workspace
EventWaitHandle waitHandle = EventWaitHandle.OpenExisting(waitHandleName);
// blocks until the wait handle is triggered by the test infrastructure
waitHandle.WaitOne();
}
}