question anbout control.invoke and control.begininvoke

  • Thread starter Thread starter C#
  • Start date Start date
C

C#

who kowns the difference beteewn
control.invoke and control.begininvoke?
I cann't find any diffrence from them
please tell me detail about it
thanks a lot
 
Hi,

Some methods have the option to execute on a separate thread (asynchronous). They are called the same as the synchronous method but have a Begin and End. So, Control.Invoke is done in the same thread that calls the method, while Control.BeginInvoke is done on a separate thread.

Happy coding!
Morten Wennevik [C# MVP]
 
Morten Wennevik said:
Some methods have the option to execute on a separate thread
(asynchronous). They are called the same as the synchronous method
but have a Begin and End. So, Control.Invoke is done in the same
thread that calls the method, while Control.BeginInvoke is done on a
separate thread.

No, that's not true at all. The whole *point* of Control.Invoke is that
the delegate is *not* executed on the thread which calls it - it's
executed on the UI thread for the control.

The difference between Control.BeginInvoke and Control.Invoke is that
Control.Invoke blocks the calling thread until the delegate has
finished executing in the UI thread, whereas Control.BeginInvoke
doesn't. The delegate is executed in the UI thread either way.
 
Um, wouldn't BeginInvoke (not the delegate) execute on a separate thread from the caller thread? Since both provide a result available to the caller.

Happy coding!
Morten Wennevik [C# MVP]
 
Morten Wennevik said:
Um, wouldn't BeginInvoke (not the delegate) execute on a separate
thread from the caller thread? Since both provide a result available
to the caller.

BeginInvoke itself executes on the thread you call it on, for all
classes - it's just a method. It may happen to cause something else to
execute in a different thread (e.g. a ThreadPool thread) as well, of
course - I don't know whether that's the case for Control.BeginInvoke
or not.

The important difference between Control.Invoke and Control.BeginInvoke
is the blocking behaviour though.
 
Back
Top