diff --git a/source/NetCoreServer/SslClient.cs b/source/NetCoreServer/SslClient.cs index 3a4f643..9a8de12 100644 --- a/source/NetCoreServer/SslClient.cs +++ b/source/NetCoreServer/SslClient.cs @@ -581,7 +581,7 @@ public virtual string Receive(long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); diff --git a/source/NetCoreServer/SslSession.cs b/source/NetCoreServer/SslSession.cs index 552980a..2bdfa1e 100644 --- a/source/NetCoreServer/SslSession.cs +++ b/source/NetCoreServer/SslSession.cs @@ -429,7 +429,7 @@ public virtual string Receive(long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); diff --git a/source/NetCoreServer/TcpClient.cs b/source/NetCoreServer/TcpClient.cs index 273da1f..6c17f12 100644 --- a/source/NetCoreServer/TcpClient.cs +++ b/source/NetCoreServer/TcpClient.cs @@ -514,7 +514,7 @@ public virtual string Receive(long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); @@ -694,6 +694,7 @@ private void ProcessReceive(SocketAsyncEventArgs e) if (!IsConnected) return; + bool recursive = (Thread.CurrentThread.ManagedThreadId == _receiveThreadId); long size = e.BytesTransferred; // Received some data from the server @@ -719,7 +720,7 @@ private void ProcessReceive(SocketAsyncEventArgs e) // If zero is returned from a read operation, the remote end has closed the connection if (size > 0) { - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (recursive) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); @@ -744,6 +745,7 @@ private void ProcessSend(SocketAsyncEventArgs e) if (!IsConnected) return; + bool recursive = (Thread.CurrentThread.ManagedThreadId == _sendThreadId); long size = e.BytesTransferred; // Send some data to the server @@ -774,7 +776,7 @@ private void ProcessSend(SocketAsyncEventArgs e) // Try to send again if the client is valid if (e.SocketError == SocketError.Success) { - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (recursive) ThreadPool.QueueUserWorkItem(_ => TrySend()); else TrySend(); diff --git a/source/NetCoreServer/TcpSession.cs b/source/NetCoreServer/TcpSession.cs index c315403..d4344e3 100644 --- a/source/NetCoreServer/TcpSession.cs +++ b/source/NetCoreServer/TcpSession.cs @@ -397,7 +397,7 @@ public virtual string Receive(long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); @@ -526,6 +526,7 @@ private void ProcessReceive(SocketAsyncEventArgs e) if (!IsConnected) return; + bool recursive = (Thread.CurrentThread.ManagedThreadId == _receiveThreadId); long size = e.BytesTransferred; // Received some data from the client @@ -552,7 +553,7 @@ private void ProcessReceive(SocketAsyncEventArgs e) // If zero is returned from a read operation, the remote end has closed the connection if (size > 0) { - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (recursive) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); @@ -577,6 +578,7 @@ private void ProcessSend(SocketAsyncEventArgs e) if (!IsConnected) return; + bool recursive = (Thread.CurrentThread.ManagedThreadId == _sendThreadId); long size = e.BytesTransferred; // Send some data to the client @@ -608,7 +610,7 @@ private void ProcessSend(SocketAsyncEventArgs e) // Try to send again if the session is valid if (e.SocketError == SocketError.Success) { - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (recursive) ThreadPool.QueueUserWorkItem(_ => TrySend()); else TrySend(); diff --git a/source/NetCoreServer/UdpClient.cs b/source/NetCoreServer/UdpClient.cs index fa5d062..4f4159a 100644 --- a/source/NetCoreServer/UdpClient.cs +++ b/source/NetCoreServer/UdpClient.cs @@ -551,7 +551,7 @@ public virtual string Receive(ref EndPoint endpoint, long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive(); diff --git a/source/NetCoreServer/UdpServer.cs b/source/NetCoreServer/UdpServer.cs index 9962cbb..4ef0a02 100644 --- a/source/NetCoreServer/UdpServer.cs +++ b/source/NetCoreServer/UdpServer.cs @@ -544,7 +544,7 @@ public virtual string Receive(ref EndPoint endpoint, long size) public virtual void ReceiveAsync() { // Try to receive datagram - if (Thread.CurrentThread.ManagedThreadId == _sendThreadId) + if (Thread.CurrentThread.ManagedThreadId == _receiveThreadId) ThreadPool.QueueUserWorkItem(_ => TryReceive()); else TryReceive();