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.