Let's say I have this code :
public class MyAsyncHandler : IHttpAsyncHandler
{
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
MyAsynchOperation asynch = new MyAsynchOperation(cb, context, extraData);
asynch.StartAsyncWork();
return asynch;
}
//...
Now , if MyAsynchOperation
is an IO operation , so it probably have internal methods (APM) of BeginFOO/EndFOO
which are not tying a thread.
When the operation is finished , a new/same thread from the thread pool (via completion ports) is dealing with the response.
All ok.
But one of the things which makes me wonder is that IAsyncResult
has this property :
System.Threading.WaitHandle AsyncWaitHandle { get; }
I'm familiar with WaitHadnle
that it has a methods to block the current thread.
A thread waits, or blocks, at the turnstile by calling WaitOne
(for example).
And so here is my questions :
Question #1
- Assuming
MyAsynchOperation
is using the APM for IO , How(for what) doeswaitHAndle
is being used if there is no blocking/tying a thread ?
Question #2
- Assuming
MyAsynchOperation
is NOT using the APM and it's just my implementation which internally callsnew Thread().start(do some calculation)
which I later later callAsyncCallback's
Callback
---- doeswaithandle
here blocks a thread ?