What happens when a synchronous method is called within an asynchronous callback?
Example:
private void AcceptCallback(IAsyncResult AR)
{
tcp.BeginReceive(ReceiveCallback);
}
private void ReceiveCallback(IAsyncResult AR)
{
tcp.Send(data);
}
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?
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 (whichTcpClient
andUdpClient
use internally), where overlapped IO is used to invoke the callback (see the comment on top ofasyncResult.SetUnmanagedStructures
invocation: