Languages
[Edit]
EN

C#/.NET - create thread with parameters

4 points
Created by:
Kate_C
21340

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...

References

  1. Thread Class - Microsoft Docs
  2. ParameterizedThreadStart Delegate - Microsoft Docs
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join