我不知道如何在异步方法等待传入连接时正确关闭TcpListener。我在SO上找到了这段代码,这里是代码:publicclassServer{privateTcpListener_Server;privatebool_Active;publicServer(){_Server=newTcpListener(IPAddress.Any,5555);}publicasyncvoidStartListening(){_Active=true;_Server.Start();awaitAcceptConnections();}publicvoidStopListening(){_Active=