C#: How to set AsyncWaitHandle in Compact Framework?

Posted by Thorsten Dittmar on Stack Overflow See other posts from Stack Overflow or by Thorsten Dittmar
Published on 2010-03-16T16:18:32Z Indexed on 2010/03/16 16:21 UTC
Read the original article Hit count: 560

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about compact-framework