EN
C#/.NET - create thread with parameters
4
points
To run new thread with parameters in C#/.NET Thread
class and ParameterizedThreadStart
delegate can be used.
Thread with parameters example
using System;
using System.Threading;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Thread thread = new Thread((object parameters) =>
//Thread thread = new Thread(new ParameterizedThreadStart((object parameters) =>
{
string text = (string)parameters;
//MyType variable = (MyType)parameters;
Console.WriteLine(text);
}));
thread.Start("My parameter...");
//MyType variable = new MyType();
//thread.Start(variable);
}
}
}
Output:
My parameter...