I am working on a Windows CE 5.0 application from .NET CF 3.5 SP1. I want to simulate a socket receiving timeout and write some codes:
... AutoResetEvent auto = new AutoResetEvent(false); mySocket.BeginReceiveFrom(arrData, 0, 4, SocketFlags.None, ref EP, new AsyncCallback(ReceiveCallback), mySocket); //if (auto.WaitOne(10000,false)) or : if (auto.WaitOne()) { // program flow never comes here, even after setting signal! _log.AppendLine("Message receive success"); } ...
and here is my callback method:
void ReceiveCallback(IAsyncResult ar) { bool b = ((EventWaitHandle)ar.AsyncWaitHandle).Set(); _log.AppendLine(string.Format("AsyncWaitHandle.Set() called and returned {0}",b)); }
as I tested the application and registered some information, I immediately get the data, and ar.AsyncWaitHandle.Set () returns true, but why does the program flow never end? what's wrong?
losingsleeep
source share