Invoking a delegate question

I would like to learn about the Invoke (delegate) method. I do not understand why I do not need to specify arguments. What if I need them to supply ... I hope you understand better what I mean. Thanks you

 EventHandler a = new EventHandler(this.A);
            Invoke(a); //where doest it take the arguments from?

            a(); //does not work, missing arguments
+3
source share
2 answers

Because Invoke is intended to be used on Windows Forms, and the template for the events used here is well-defined, the Invoke method can make a reasonable guess. In fact, it is documented on MSDN exactly what it does if you try to call EventHandler without parameters using Invoke:

EventHandler, , EventArgs.Empty.

Invoke, , , . , Invoke EventHandler (, , , ).

+6

EventHandlers, . , , , :

a.Invoke(new object[] { arg0, .... argn });
0

Source: https://habr.com/ru/post/1735774/


All Articles