How to call a function though Control.BeginInvoke in a signal-slot-like fashion?

Posted by Dimitri C. on Stack Overflow See other posts from Stack Overflow or by Dimitri C.
Published on 2010-04-22T08:04:53Z Indexed on 2010/04/22 8:43 UTC
Read the original article Hit count: 218

Filed under:
|
|

I'd like a delegate that calls a function in a different thread when it is invoked. Currently, I'm using the following implementation:

delegate void someFunctionDelegate();
//...

someFunctionDelegate callBackFunction = someForm.SomeFunction;
someForm.Invoke(someFunctionDelegate);

However, I'd like a more compact form, combining both the someForm instance and the SomeForm.SomeFunction member function. I'm thinking of something like this:

var callBackFunction = new AsynchronousCrossThreadDelegate(someForm, SomeForm.SomeFunction);
callBackFunction(); // Should call someForm.BeginInvoke(SomeForm.SomeFunction);

Is there a way to do so in C#/.NET?

Update I'm looking for a solution that will work for functions with 0 or more parameters.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET