From: Tony Johansson on
Hi!

I just want to make sure that I have understood this correct.
When I use asynchronsous(wait-until-done) with for example a BeginRead
a new thread is started internally to perform this asynchronous BeginRead.
This thread is processing to complete the asynchronous call.
Is this correct understood ?

One thing that talk againt this is that when I for example do the BeginRead
and look at the Debug->Window->Threads dialog screen I can't see any
additional thread is working but there might be internal threads that is not
shown on this dialog screen.

When the main thread is calling the asynchronous EndRead the main thread is
blocked if the asynchronous EndRead call is not complete. If it is complete
then the main thread is not blocked.

Now to my question there must be some communication between the additional
thread that is performing the
asynchronous read and the main thread because if the additional thread is
not complete the main thread is blocked. ??

//Tony


From: Willem van Rumpt on
Tony Johansson wrote:
> Hi!
>
> I just want to make sure that I have understood this correct.
> When I use asynchronsous(wait-until-done) with for example a BeginRead
> a new thread is started internally to perform this asynchronous BeginRead.
> This thread is processing to complete the asynchronous call.
> Is this correct understood ?

Yes, unless the inner mechanism of the specific implementation determine
it's better to complete the request synchronously.

>
> One thing that talk againt this is that when I for example do the BeginRead
> and look at the Debug->Window->Threads dialog screen I can't see any
> additional thread is working but there might be internal threads that is not
> shown on this dialog screen.
>

That might be because of synchronous completion. The thread window
should show them as a worker thread, originating from the ThreadPool.

> When the main thread is calling the asynchronous EndRead the main thread is
> blocked if the asynchronous EndRead call is not complete. If it is complete
> then the main thread is not blocked.
>

Correct.

> Now to my question there must be some communication between the additional
> thread that is performing the
> asynchronous read and the main thread because if the additional thread is
> not complete the main thread is blocked. ??
>

The IAsyncResult returned by BeginXXXX has a wait handle that can be
waited on until it's signalled. I haven't checked the implementations,
but presumably EndRead in it's simplest form makes a call to
IAsyncResult.ASyncWaitHandle.WaitOne().

--
Willem van Rumpt