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

CsharpProgrammingServer Side Programming

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
raja
Published on 31-Aug-2018 08:30:25
Advertisements