I used the following code to send data asynchronously, but I noticed that using WaitOne in AsyncWaitHandle, which I get from asyncRes , does not wait at all. I checked the MSDN and said that I should use ManualResetEvent.
...
var asyncRes = _socket.BeginSend(encodedFrame, 0, encodedFrame.Length, SocketFlags.None, sendCallback, _socket);
...
var success = asyncRes.AsyncWaitHandle.WaitOne(_timeout, true);
...
private void sendCallback(IAsyncResult ar)
{
_socket.EndSend(ar);
}
MSDN also says in IAsyncResult:
AsyncWaitHandle: returns WaitHandle, which is used to wait for the completion of the asynchronous operation.
So why can't I use it for this purpose?
Thank.
source
share