What is the use of Invoke () in .net?

I found this code:

this.Invoke(new EventHandler(EventGetSum));

This is not the same as writing:

EventGetSum();

What use is this?

+5
source share
3 answers

If you write EventGetSum()that immediately calls the EventGetSum method.

If you write new EventHandler(EventGetSum), which creates a delegate, which (in turn) calls EventGetSum when it is called.

A call Control.Invokeinvokes this delegate from the user interface thread responsible for the control. This is necessary because you should not access user interface elements from arbitrary threads.

+13
source

EventGetSum , this.

+5

This is usually used when referring to user calls with cross-flow.

See the MSDN documentation for ISynchronizeInvoke.

+4
source

All Articles