How to start a Thread in C#

By | December 5, 2017

We have to use the Thread class provided by System.Threading namespace. In the constructor of the class, we have to pass the method name which we want to run in separate thread. After than we have to call the start method of Thread class.

Example:-

using System;
using System.Threading;
 
namespace ConsoleApplication1
{
 class Program
 {
 static void Main(string[] args)
 {
 Thread th = new Thread(ThreadMethod);
 th.Start();
 }
 
 private static void ThreadMethod()
 {
 Console.WriteLine("Another Thread");
 }
 }
}

 

Note:- When we are creating one or more threads or collection of threads during the initialization of a Multi-threading environment and then instead of going it to a garbage collection it directly adds it to the thread pool for reusability of those threads for same task or new task. This process is called Thread Pooling.

Like it? Share it