How to obtain Status of the Current Thread in C#?


To get the status of current thread, use the IsAlive() method −

Firstly, create a new thread −

Thread t = Thread.CurrentThread;
t.Name = "Our Thread";

Now, to get the status of the current thread −

t.IsAlive

The following is the complete code −

Example

 Live Demo

using System;
using System.Threading;

namespace Demo {
   class MyClass {
      static void Main(string[] args) {
         Thread t = Thread.CurrentThread;
         t.Name = "Our Thread";

         Console.WriteLine("Status = {0}", t.IsAlive);
         Console.ReadKey();
      }
   }
}

Output

Status = True

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 22-Jun-2020

158 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements