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.
xxxxxxxxxx
1
using System;
2
using System.Threading;
3
4
namespace Test
5
{
6
class Program
7
{
8
static void Main(string[] args)
9
{
10
Thread thread = new Thread((object parameters) =>
11
//Thread thread = new Thread(new ParameterizedThreadStart((object parameters) =>
12
{
13
string text = (string)parameters;
14
//MyType variable = (MyType)parameters;
15
16
Console.WriteLine(text);
17
}));
18
19
thread.Start("My parameter...");
20
21
//MyType variable = new MyType();
22
//thread.Start(variable);
23
}
24
}
25
}
Output:
xxxxxxxxxx
1
My parameter...