0

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?

Clemens
  • 123,504
  • 12
  • 155
  • 268
yaho cho
  • 1,779
  • 1
  • 7
  • 19

1 Answers1

1

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.

pseudorian
  • 184
  • 1
  • 9