all groups > dotnet windows forms > november 2007 >
You're in the

dotnet windows forms

group:

"Posting" a method call to the UI thread



"Posting" a method call to the UI thread Eric Dan
11/27/2007 8:13:02 AM
dotnet windows forms: 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.


--
Thanks
Re: "Posting" a method call to the UI thread Eric Dan
11/27/2007 8:30:01 PM
My mistake.

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

--
Thanks
Eric


[quoted text, click to view]
Re: "Posting" a method call to the UI thread Mattias Sjögren
11/27/2007 8:56:39 PM
[quoted text, click to view]

What makes you say that?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Re: "Posting" a method call to the UI thread Brian Gideon
11/30/2007 7:08:52 AM
[quoted text, click to view]

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
AddThis Social Bookmark Button