diff --git a/NHttp/HttpServer.cs b/NHttp/HttpServer.cs index b9fdd7b..20b6c99 100644 --- a/NHttp/HttpServer.cs +++ b/NHttp/HttpServer.cs @@ -249,6 +249,8 @@ private void AcceptTcpClientCallback(IAsyncResult asyncResult) { try { + BeginAcceptTcpClient(); // Do this first so as exception below doesn't interrupt listening + var listener = _listener; // Prevent race condition. if (listener == null) @@ -268,9 +270,7 @@ private void AcceptTcpClientCallback(IAsyncResult asyncResult) RegisterClient(client); - client.BeginRequest(); - - BeginAcceptTcpClient(); + client.BeginRequest(); } catch (ObjectDisposedException) {