AsyncWaitHandle and EndInvoke

E

Eric Twietmeyer

Hello,

I can't find any indication in the docs whether the AsyncWaitHandle will be
signalled if in an async callback the call to EndInvoke throws an exception,
meaning that the call failed in some way.

Also in the "Notes to Implementers" in the docs for
IAsyncResult.AsyncWaitHandle it indicates that the "object behind
AsyncWaitHandle can be discarded" after the user calls the method that
concludes the asynchronous operation (EndInvoke). So it "can be discarded".
But is it? Do I need to call .Close on this wait handle?

Thanks,

-Eric Twietmeyer
 
W

William Stacey [MVP]

Working on memory here... The waithandle is signaled before the callback run
on thread pool thread. It would have to work that way if you just wanted to
wait on the handle and not use a callback. But you still need to call
EndInvoke using either method (wait on handle or callback.) The wait handle
is collected when the internal async state object goes out of scope so you
don't need to do anything as it is a managed wait object. This is the
reason you need to call EndInvoke so the internal state object can be
removed from the array that holds pending async requests - or else you would
leak memory. HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top