Main thread vs child thread in C#


Main Thread

The first thread to be executed in a process is called the main thread. When a C# program starts execution, the main thread is automatically created.

Child Thread

The threads created using the Thread class are called the child threads of the main thread.

Here is an example showing how to create a main and child thread −

Example

 Live Demo

using System;
using System.Threading;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         Thread th = Thread.CurrentThread;
         th.Name = "MainThread";
         Console.WriteLine("This is {0}", th.Name);
         Console.ReadKey();
      }
   }
}

Output

This is MainThread

Updated on: 22-Jun-2020

581 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements