VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/check-whether-a-thread-is-alive-or-not-in-c-sharp/

⇱ How to Check Whether a Thread is Alive or Not in C#? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Check Whether a Thread is Alive or Not in C#?

Last Updated : 11 Jul, 2025

A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as IsAlive to check if the thread is alive or not. In other words, the value of this property indicates the current execution of the thread.

Example 1: This example demonstrates how to check the state of the main thread using the IsAlive property.


Output
Is the main thread alive? : True

Explanation: In this example, we check the state of the main thread using Thread.CurrentThread. The IsAlive property returns true because the main thread is alive as long as the program is running.

Syntax of IsAlive Property

public bool IsAlive { get; }

Return Type: This property returns "true" if the thread is started and not terminated normally or aborted, otherwise, return "false". The return type of this property is bool (boolean).

Example 2: This example demonstrates how to check whether custom threads (not the main thread) are alive by using the IsAlive property.


Output
Is thread 1 is alive : False
Is thread 2 is alive : False
Is thread 1 is alive : True
Is thread 2 is alive : True

Explanation: In the above example,

  • Before the threads are started, both T1.IsAlive and T2.IsAlive return false because the threads have not started yet.
  • After calling Start(), the threads begin executing. However, the IsAlive check immediately after starting might still return false due to timing and thread scheduling.
  • After the Thread.Sleep(500), both threads should be alive, so IsAlive returns true for both threads.

Note: If you want to ensure the threads have completed their execution before checking their status again, you could use T1.Join() and T2.Join() to block the main thread until both threads finish executing.

Comment

Explore