C# Program to display name of Current Thread


To display the name of the current thread in C#, use the Name property.

Firstly, use the currentThread property to display information about a thread −

Thread thread = Thread.CurrentThread;

Now use the thread.Name property to display name of the thread −

thread.Name

Example

Let us see the complete code show current thread’s name in C#.

Live Demo

using System;
using System.Threading;
namespace Demo {
   class MyClass {
      static void Main(string[] args) {
         Thread thread = Thread.CurrentThread;
         thread.Name = "My Thread";
         Console.WriteLine("Thread Name = {0}", thread.Name);
         Console.ReadKey();
      }
   }
}

Output

Thread Name = My Thread

Updated on: 19-Jun-2020

164 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements