C# Program to Check status of Current Thread


To check the status of the current thread in C#, use the IsAlive property.

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

Thread thread = Thread.CurrentThread;

Now use the thread.IsAlive property to check the status of the thread −

thread.IsAlive

Example

Let us see the complete code to check the status of current thread 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 New Thread";
         Console.WriteLine("Thread Status = {0}", thread.IsAlive);
         Console.ReadKey();
      }
   }
}

Output

Thread Status = True

Updated on: 19-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements