Home »
.Net »
C# Programs
C# program to print the name of the current thread
Name of the current thread in C#: Here, we are going to learn how to print the name of the current thread in C#?
Submitted by Nidhi, on August 16, 2020
To solve the above problem, here we created using Thread.CurrentThread property then we assign thread name and then print thread information.
Program:
/*
* 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.
C# Thread Programs »