An AsyncCallback after Socket.BeginReceive is not called while the server is being initialized during startup.

mSocket.BeginReceive(mBuffer, 0, mBuffer.Length, SocketFlags.None, new AsyncCallback(onReceive), mSocket);
private void onReceive(IAsyncResult result)
{
    if (mSocket == null) return;
    Monitor.Enter(mLockObj);
    mSocket.EndReceive(result);
    //...                       

Do I need to create some timeout logic or is there an exception case I can catch and handle?

1 Answers

1
pseudorian On Best Solutions

Because the AsyncCallback is, well, async, it will be waiting to receive indefinitely until it returns, so there will be no "timeout" exception.

Some options were explored in this thread, but, to answer your question, you'll essentially have to implement your own timeout method.