DotnetCore2:HttpListener不在Ubuntu上工作

DotnetCore2:HttpListener不在Ubuntu上工作,ubuntu,.net-core,httplistener,Ubuntu,.net Core,Httplistener,以下使用HTTPListener的DotNet Core 2项目在Windows上运行时有效,但在Ubuntu上运行时抛出HttpListenerException static void Main(string[] args) { Console.WriteLine("Started."); HttpListener listener = new HttpListener(); listener.Prefixes.Add(@"

以下使用HTTPListener的DotNet Core 2项目在Windows上运行时有效,但在Ubuntu上运行时抛出HttpListenerException

    static void Main(string[] args)
    {
        Console.WriteLine("Started.");

        HttpListener listener = new HttpListener();

        listener.Prefixes.Add(@"http://+:83/");

        listener.Start();


        ThreadPool.QueueUserWorkItem((c) =>
        {
            Console.WriteLine("Webserver processing...");
        }, listener.GetContext());

        listener.Stop();

        listener.Close();
        Console.WriteLine("Stopped.");
    }
在Windows上,我运行该进程,然后进行浏览。该流程无投诉退出:

Started.
Webserver processing...
Stopped.
但在Ubuntu上,我运行该过程,然后浏览:

Started.
Webserver processing...

Unhandled Exception: System.Net.HttpListenerException: Address already in use 
at System.Net.HttpEndPointManager.GetEPListener(String host, Int32 port, HttpListener listener, Boolean secure)
at System.Net.HttpEndPointManager.RemovePrefixInternal(String prefix, HttpListener listener)
at System.Net.HttpEndPointManager.RemoveListener(HttpListener listener)
at System.Net.HttpListener.Close(Boolean force)
at System.Net.HttpListener.Dispose()
at System.Net.HttpListener.Close()
at ListenTest.Program.Main(String[] args) in Program.cs:line 30
Aborted
所以它会抛出listener.Close()

我可以捕获HttpListenerException并忽略它,但下次运行该进程时,它会在listener.Start()上抛出相同的错误和消息。由于它不会在我第一次运行它时释放套接字,所以我需要等待一两分钟,然后操作系统才会释放套接字/端口以供重用

如果我注释掉ThreadPool.QueueUserWorkItem()调用,以禁止浏览端口,那么程序将很好地退出,而不会抛出

如果您有任何想法可以在Ubuntu上使用,我们将不胜感激!:)

更新:
这将在.NetCore 2.1.0中修复(根据)

这将在.NetCore 2.1.0中修复(根据)

对我来说,听起来像是.NetCore 2.0中的一个bug。我可以自己复制。它应该在退出时释放端口。将更新作为答案发布并接受它。