Parameterized Methods
Learn to execute parameterized methods on threads.
We'll cover the following...
We'll cover the following...
The ParameterizedThreadStart delegate
Running a parameterless method on a thread is achieved by passing an instance of the ThreadStart delegate to a Thread constructor. What if we need to pass some parameters to the thread? The ParameterizedThreadStart delegate is used for this purpose:
public Thread(ParameterizedThreadStart start)
{
}
The ParameterizedThreadStart delegate has the following definition:
public delegate void ParameterizedThreadStart(object obj);
Using this delegate is no different than creating a thread with ThreadStart. Here’s an example: