In order to represent the method that executes on a thread I am using and passing the name of the method. In this case the method name is
ParameterizedThreadStartSelectJob and the instantiation is as follows:
ParameterizedThreadStart starter = new ParameterizedThreadStart(SelectJob);
protected void SelectJob(object index)
{
...
}
In order to reuse a portion of code I would like, if possible, to store the method name in a variable but the IntelliSense shows the method signature for ParameterizedThreadStart as ParameterizedThreadStart(void (object) target) and I’m not sure how I could store this sort of value. From MSDN I realize this is a delegate so after reading How to: Declare, Instantiate, and Use a Delegate I tried to declare …
delegate void Del(string str);
Del selectDelegate = SelectJob;
… but since the SelectJob method is not static I am not able to do this. Simply making the method static is not an easy option.
Is there another way of making this declaration?
Thanks!
Initialise the delegate instance inside a constructor?