/*
* Program to print the Name of the Current Thread
*/
using System;
using System.Threading;
class MyThreadClass
{
static void Main(string[] args)
{
Thread t = Thread.CurrentThread;
t.Name = "MyNewThread";
Console.WriteLine("Thread information:");
Console.WriteLine("\tName of the thread: "+t.Name);
Console.WriteLine("\tStatus of thread : "+(t.IsAlive==true?"Alive":"Not Alive"));
}
}
Output:
Thread information:
Name of the thread: MyNewThread
Status of thread : Alive
Press any key to continue . . .
Explanation:
In the above program, we created a class MyThreadClass that contains the Main() method to start the execution of the program. In the Main() method, we created using Thread.CurrentThread property then we assigned thread name and then print thread information.
Program:
Output:
Thread information: Name of the thread: MyNewThread Status of thread : Alive Press any key to continue . . .Explanation:
In the above program, we created a class MyThreadClass that contains the Main() method to start the execution of the program. In the Main() method, we created using Thread.CurrentThread property then we assigned thread name and then print thread information.
need an explanation for this answer? contact us directly to get an explanation for this answer