a.kostrzewa said:
Yes, of course.
I call asynchronous read operation in this way:
IAsyncResult oResult = oSocket.BeginReceive(...);
oWH = m_oResult .AsyncWaitHandle;
// oEventsHandler - my class object
oEventsHandler.WaitForGroupEQ(Timeout.Infinite ,nGroupId,out nEvent);
int nNumberOfBytesRead = ReadEnd();
But I can't break this operation.
Olek -
From what I can tell from your code it looks like you are blocking
the main thread until the EndReceive() callback method fires. This
somewhat defeats the purpose of using an asynchronous socket call.
Instead of waiting indefinitely for an answer, why don't you put a
reasonable timeout time in the WaitForGroupEQ method. When the timeout
is reached you know there wasn't a response. If you then Close() the
Socket object, the EndReceive() method will fire, and throw an
Exception. You should catch the Exception in a try-catch block and
handle it accordingly.
Alternatively, you can use the blocking Receive() method, and set
the ReceiveTimeout Socket option property to a reasonable value. The
Receive() method will throw an Exception if the timeout is reached
before data is received. Hope this helps solve your problem.
Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html