Naming a thread and fetching name of current thread in C# Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report A thread is a light-weight process within a process. In C#, a user is allowed to assign a name to the thread and also find the name of the current working thread by using the Thread.Name property of the Thread class. Syntax : public string Name { get; set; } Here, the string contains the name of the thread or null if no name was assigned or set. Important Points: The by default value of the Name property is null. The string given to the name property can include any Unicode Character. The name property of Thread class is write-once. If a set operation was requested, but the Name property has already set, then it will give InvalidOperationException. Example 1: CSharp // C# program to illustrate the // concept of assigning names // to the thread and fetching // name of the current working thread using System; using System.Threading; class Geek { // Method of Geek class public void value() { // Fetching the name of // the current thread // Using Name property Thread thr = Thread.CurrentThread; Console.WriteLine("The name of the current "+ "thread is: " + thr.Name); } } // Driver class public class GFG { // Main Method static public void Main() { // Creating object of Geek class Geek obj = new Geek(); // Creating and initializing threads Thread thr1 = new Thread(obj.value); Thread thr2 = new Thread(obj.value); Thread thr3 = new Thread(obj.value); Thread thr4 = new Thread(obj.value); // Assigning the names of the threads // Using Name property thr1.Name = "Geeks1"; thr2.Name = "Geeks2"; thr3.Name = "Geeks3"; thr4.Name = "Geeks4"; thr1.Start(); thr2.Start(); thr3.Start(); thr4.Start(); } } Output: The name of the current thread is: Geeks2 The name of the current thread is: Geeks3 The name of the current thread is: Geeks4 The name of the current thread is: Geeks1 Example 2: CSharp // C# program to illustrate the // concept of giving a name to thread using System; using System.Threading; class Name { static void Main() { // Check whether the thread // has already been named // to avoid InvalidOperationException if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "MyThread"; Console.WriteLine("The name of the thread is MyThread"); } else { Console.WriteLine("Unable to name the given thread"); } } } Output: The name of the thread is MyThread Reference: https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.name?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article Thread.CurrentThread Property in C# A ankita_saini Follow Improve Article Tags : C# CSharp Multithreading CSharp Thread Class Similar Reads C# | Getting the unique identifier for the current managed thread A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as ManagedThreadId to check the unique identifier for the current managed thread. Or in other words, the value of ManagedThreadId property of a thread defines uniquely that thre 2 min read Suspending the current thread for the specified amount of time in C# In C#, a Sleep() method temporarily suspends the current execution of the thread for specified milliseconds, so that other threads can get the chance to start the execution, or may get the CPU for execution. There are two methods in the overload list of Thread.Sleep Method as follows: Sleep(Int32) S 3 min read C# | Check if a thread belongs to managed thread pool or not A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as IsThreadPoolThread to check if the thread belongs to the managed thread pool or not. Syntax: public bool IsThreadPoolThread { get; } Return Value: This property returns true 2 min read How to check whether a thread is a background thread or not in C# As we know that thread is created and managed by the Thread class. So, the Thread class provides a property known as IsBackground property to check whether the given thread is running in the background or in the foreground. If the value of IsBackground is set to be true, then it means the thread is 3 min read Thread.CurrentThread Property in C# A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as CurrentThread to check the current running thread. Or in other words, the value of this property indicates the current running thread. Syntax: public static Thread CurrentThr 2 min read C# | How to check current state of a thread A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as ThreadState to check the current state of the thread. The initial state of a thread is Unstarted state. Syntax: public ThreadState ThreadState{ get; } Return Value: This prop 2 min read Like