1.

What is the first thread that is created and executed inside a process in C#?

Answer»

The Main Thread is the first thread that is created and executed inside a process. It is AUTOMATICALLY created when the process starts execution.

A program that demonstrates the Main thread is given as follows:

using System; using System.Threading; namespace MultithreadingDemo {   class Example   {      static void Main(string[] args)      {         Thread myThread = Thread.CurrentThread;         myThread.NAME = "Main_Thread";         Console.WriteLine("This thread is the {0}", myThread.Name);      }   } }

The output of the above program is as follows:

This thread is the Main_Thread

Now let US understand the above program.

The CurrentThread PROPERTY of the Thread class is used to access the Main thread. The name of the thread is specified is Main_Thread. After that, this is displayed. The code snippet for this is given as follows:

Thread myThread = Thread.CurrentThread; myThread.Name = "Main_Thread";          Console.WriteLine("This thread is the {0}", myThread.Name);


Discussion

No Comment Found