Run delegation method using BeginInvoke

In my class I have a static method

public static void DoWork(int param) ...

I want to run this method, for example:

Form.BeginInvoke(DoWork, param);

Is this operation possible?

I tried with the MethodInvoker class ... but I do not want to define the body of the inline method. Is there a common delegate? Or do you know any other way to call this without defining a delegate ( private delegate void DoWorkDelegate(int param)) object ?

+3
source share
1 answer

You should be able to use:

form.BeginInvoke((Action<int>)DoWork, param);

MethodInvoker - , typed-invoke, , , , ; :

form.BeginInvoke((MethodInvoker)delegate {DoWork(param);});
+8

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


All Articles