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


C# HttpListener.Close方法代码示例

本文整理汇总了C#中HttpListener.Close方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.Close方法的具体用法?C# HttpListener.Close怎么用?C# HttpListener.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpListener的用法示例。


在下文中一共展示了HttpListener.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        Console.Title = "Samples.CustomChecks.3rdPartySystem";
        Console.WriteLine("Press enter key to toggle the server to return a error or success");
        Console.WriteLine("Press any key to exit");

        using (listener = new HttpListener())
        {
            listener.Prefixes.Add("http://localhost:57789/");
            listener.Start();
            listener.BeginGetContext(ListenerCallback, listener);

            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                Console.WriteLine();

                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }
                listener.Close();
                if (isReturningOk)
                {
                    Console.WriteLine("\r\nCurrently returning success");
                }
                else
                {
                    Console.WriteLine("\r\nCurrently returning error");
                }
                isReturningOk = !isReturningOk;
            }
        }
    }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:34,代码来源:Program.cs

示例2: Main

	static void Main ()
	{
		HttpListener listener = new HttpListener ();
		listener.IgnoreWriteExceptions = true;
		listener.Prefixes.Add ("http://*:8081/");
		listener.Start ();
		listener.BeginGetContext (RequestHandler, listener);
		while (true) {
			Thread.Sleep (250);
			if (File.Exists ("stop-server.tmp"))
				break;
		}
		listener.Close ();
		File.Create ("finish-server.tmp").Close ();
	}
开发者ID:mono,项目名称:gert,代码行数:15,代码来源:server.cs

示例3: UrlPrefix

        static UrlPrefix()
        {
            // Find a URL prefix that is not in use on this machine *and* uses a port that's not in use.
            // Once we find this prefix, keep a listener on it for the duration of the process, so other processes
            // can't steal it.

            Guid processGuid = Guid.NewGuid();

            for (int port = 1024; port <= IPEndPoint.MaxPort; port++)
            {
                string prefix = $"http://localhost:{port}/{processGuid:N}/";

                var listener = new HttpListener();
                try
                {
                    listener.Prefixes.Add(prefix);
                    listener.Start();

                    s_processPrefixListener = listener;
                    s_processPrefix = prefix;
                    break;
                }
                catch (Exception e)
                {
                    // can't use this prefix
                    listener.Close();

                    // Remember the exception for later
                    s_processPrefixException = e;

                    // If this is not an HttpListenerException, something very wrong has happened, and there's no point
                    // in trying again.
                    if (!(e is HttpListenerException))
                        break;
                }
            }

            // At this point, either we've reserved a prefix, or we've tried everything and failed.  If we failed,
            // we've saved the exception for later.  We'll defer actually *throwing* the exception until a test
            // asks for the prefix, because dealing with a type initialization exception is not nice in xunit.
        }
开发者ID:dotnet,项目名称:corefx,代码行数:41,代码来源:UrlPrefix.cs


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