What happens when a synchronous method is called within an asynchronous callback?
private void AcceptCallback(IAsyncResult AR)
private void ReceiveCallback(IAsyncResult AR)
A connection is accepted and the async receive callback is started. When the tcp connection receives data, it calls the receive callback.
If the sync Send method is called, does that stop other async callbacks from happening?
Or are all async callbacks independent of each other?
Best How To :
Callbacks are independent as they're invoked on the thread-pools IO completion workers.
If you're interested, you can see that in the source code. This particular method is for the
Socket class (which
UdpClient use internally), where overlapped IO is used to invoke the callback (see the comment on top of
private void DoBeginReceiveFrom(byte buffer, int offset,
int size, SocketFlags socketFlags,
EndPoint endPointSnapshot, SocketAddress
socketAddress, OverlappedAsyncResult asyncResult)
EndPoint oldEndPoint = m_RightEndPoint;
SocketError errorCode = SocketError.SocketError;
// Set up asyncResult for overlapped WSARecvFrom.
// This call will use completion ports on WinNT and Overlapped IO on Win9x.
buffer, offset, size,
socketAddress, true /* pin remoteEP*/,
asyncResult.SocketAddressOriginal = endPointSnapshot.Serialize();
if (m_RightEndPoint == null)
m_RightEndPoint = endPointSnapshot;
errorCode = UnsafeNclNativeMethods.OSSOCK.WSARecvFrom(
errorCode = (SocketError)Marshal.GetLastWin32Error();
m_RightEndPoint = oldEndPoint;
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);