当前位置: 首页>>代码示例>>C#>>正文


C# HttpListener.Abort方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:53,代码来源:IDataServiceHostRunner.cs


注:本文中的HttpListener.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。