C#: How to set AsyncWaitHandle in Compact Framework?
- by Thorsten Dittmar
Hi,
I'm using a TcpClient in one of my Compact Framework 2.0 applications. I want to receive some information from a TCP server.
As the Compact Framework does not support the timeout mechanisms of the "large" framework, I'm trying to implement my own timeout-thing. Basically, I want to do the following:
IAsyncResult result = client.BeginRead(buffer, 0, size, ..., stream);
if (!result.AsyncWaitHandle.WaitOne(5000, false))
// Handle timeout
private void ReceiveFinished(IAsyncResult ar)
{
NetworkStream stream = (NetworkStream)ar.AsyncState;
int numBytes = stream.EndRead(ar);
// SIGNAL IASYNCRESULT.ASYNCWAITHANDLE HERE ... HOW??
}
I'd like to call Set for the IAsyncResult.AsyncWaitHandle, but it doesn't have such a method and I don't know which implementation to cast it to.
How do I set the wait handle? Or is it automatically set by calling EndRead? The documentation suggests that I'd have to call Set myself...
Thanks for any help!