Main thread vs child thread in C#

CsharpProgrammingServer Side Programming

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
raja
Published on 31-Aug-2018 11:14:33
Advertisements