From: DaveB on
On Jan 22, 12:06 am, Peter Duniho <no.peted.s...(a)no.nwlink.spam.com>
wrote:
> Alberto Poblacion wrote:
> > "momonga" <shira...(a)kk.iij4u.or.jp> wrote in message
> >news:dfe3cdd5-c2ae-48df-acbf-8bfb42c1d604(a)21g2000yqj.googlegroups.com...
> >> i need something like the PostMessage in win32.
> >> to order the main-thread to perform the job on befalf of the worker-
> >> thread.
>
> >    The closest equivalent would be the Post method of the
> > SynchronizationContext. In your main thread you would do something like
> > ctx=SynchronizationContext.Current;  then, in the other thread, you
> > could do ctx.Post(callback, arguments);  The callback would then be
> > executed in the main thread.
>
> >> please could you tell me how to do that?
>
> >   There is another, possibly simple way. Call the Invoke method of any
> > Control (including the form) by passing a callback delegate. The
> > callback method will be invoked in the main thread.
>
> I agree with your suggestion to use Invoke().
>
> However, note that the Control.BeginInvoke() method is basically the
> same as the SynchronizationContext.Post() method is basically the same
> as the unmanaged PostMessage() function, in that all three are a "queue
> and continue" operation, while Invoke(), Send(), and SendMessage() are
> all a "queue and wait" operation.
>
> If the OP really wants "queue and continue" semantics, they should use
> Control.BeginInvoke() instead.
>
> Pete- Hide quoted text -
>
> - Show quoted text -

There's some more explanation and background in these posts that might
help.
http://davebrooks.wordpress.com/2010/03/11/windowsformssynchronizationcontext-its-all-smoke-mirrors-and-postmessage/
http://davebrooks.wordpress.com/2007/02/12/begininvoke-the-land-of-confusion/

Dave
 | 
Pages: 1
Prev: How to dispose a XDocument?
Next: char ----> int