The ParameterizedThreadStart Delegate:
What if you want to pass a parameter to the function which you want to execute within your new thread? In that case, you cannot use the ThreadStart delegate.
You need to use the ParameterizedThreadStart delegate, as shown below:
class Program
{
static void Main(string[] args)
{
Thread newThread = new Thread(new ParameterizedThreadStart(OtherFunction));
newThread.Start("Hello");
Console.WriteLine("Main thread going off to sleep");
Thread.Sleep(1000);
Console.WriteLine("Main thread has woken up. Returning");
}
static void OtherFunction(object param)
{
Console.WriteLine("Parameter passed to OtherFunction : " + param.ToString());
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Inside the new thread. Current iteration = " + i);
Thread.Sleep(100);
}
}
}
Since the parameter is of type object, you can pretty much pass in anything you want. If you want to pass in multiple parameters, you can encapsulate them within an instance of another class you create, and then pass in that instance to the function, as shown below:
class Person
{
public String Name;
public int Age;
}
class Program
{
static void Main(string[] args)
{
Thread newThread = new Thread(new ParameterizedThreadStart(OtherFunction));
Person p = new Person();
p.Name = "Mustansir";
p.Age = 22;
newThread.Start(p);
}
static void OtherFunction(object param)
{
Person p = (Person)param;
Console.WriteLine("Person information obtained : " + p.Name);
Console.WriteLine("Person's Age : " + p.Age);
}
}

Attachments
Project Files C# Threading Samples