"Posting" a method call to the UI thread

  • Thread starter Thread starter Eric Dan
  • Start date Start date
E

Eric Dan

Hi,

Sometimes while handling an event in the UI thread I need to call some
action but I don't want it to be invoked in the context of the event (some
reentrant function calls may fail for example) but right after (in the same
UI thread) , something like PostMessage to the UI thread.

Is there an easy way in .Net / Windows Forms to "Post" a method call to the
UI thread?

Naturally, "Control.Invoke" will not help since it will identify that it is
the same thread and will execute immidiately. "BeginInvoke" is bad since it
will try to invoke on another thread.
 
"BeginInvoke" is bad since it will try to invoke on another thread.

What makes you say that?


Mattias
 
My mistake.

The "Control" implementation of "BeginInvoke" is actually the solution. It
is designed to work on the same Control thread.
 
My mistake.

The "Control" implementation of "BeginInvoke" is actually the solution. It
is designed to work on the same Control thread.

Yep, the difference is that Invoke queues a message on the message
pump thread to run the delegate and *waits* for it to be processed
whereas BeginInvoke returns immediately.
 
Back
Top