Threading, How Control.Invoke() works

L

LVP

Hello,

How does Control.Invoke(delegate) work?
Executes the specified delegate on the thread that owns the control's
underlying window handle

I am looking for Underthehood explanation.

How do Threads talk to each other? Who is the Middle Woman/Man/Machine?

Thank you,

LVP
 
P

Peter Duniho

How does Control.Invoke(delegate) work?
Executes the specified delegate on the thread that owns the control's
underlying window handle

I am looking for Underthehood explanation.

How do Threads talk to each other? Who is the Middle Woman/Man/Machine?

How much detail do you need/want?

I don't know all of the implementation details, but I can tell you that it
uses the message queue to marshal the delegate execution to the desired
thread. BeginInvoke() just puts a message in the queue along with the
necessary data that causes the control instance upon receiving the message
to actually run the delegate with the supplied parameters (if any).
Invoke() is similar, except that the calling thread is synchronized with
the execution of the delegate so that it doesn't continue until the
control's thread has actually run the delegate.

You can use Reflector to see the exact details, I believe. Alternatively,
Microsoft said they would be releasing the .NET source code for use in
debugging. I haven't been following that, but if it's not out yet it
should be soon. Then you can look at all the details directly (but it
should be like what you see in Reflector, just with perhaps better names
and comments).

Pete
 
L

LVP

Hi Pete,

I am not looking into deep details but, a bit more detail than you provided
me.

A high level diagram of how things work would be great.

Links would be great also.

Thank you,

LVP
 

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