自己的主机启动自己的主机



在控制台应用程序中,您可以像这样启动自己的主机:

string url = "http://localhost:8080";
using (WebApp.Start(url))
{
      Console.WriteLine("Server running on {0}", url);
      Console.ReadLine();
}

Console.ReadLine();

停止服务器停止。如何在类中启动服务器并阻止它停止?我会这么做吗?

    public bool keepHosting;
    public void Start()
    {
        using (WebApp.Start(serverUrl))
        {
            while (keepHosting)
            {
            }
        }
    }

我认为你可以这样做。

    public IDisposable Start()
    {
     return  WebApp.Start(serverUrl);
    }

最新更新