Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Thread.ThreadState Property

Gets a value containing the states of the current thread.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public ThreadState ThreadState { get; }

Property Value

Type: System.Threading.ThreadState
One of the ThreadState values indicating the state of the current thread. The initial value is Unstarted.

The ThreadState property provides more specific information than the IsAlive property.

Important noteImportant

Thread state is only of interest in debugging scenarios. Your code should never use thread state to synchronize the activities of threads.

The following code example demonstrates accessing the ThreadState of a thread.

using System;
using System.Threading;

class Example
{
    static void Main()
    {
        Thread newThread = 
            new Thread(new ThreadStart(ThreadMethod));

        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
        newThread.Start();

        // Wait for newThread to start and go to sleep.
        Thread.Sleep(300);
        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);

        // Wait for newThread to restart.
        Thread.Sleep(1000);
        Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
    }

    static void ThreadMethod()
    {
        Thread.Sleep(1000);
    }
}
// The example displays the following output: 
//       ThreadState: Unstarted 
//       ThreadState: WaitSleepJoin 
//       ThreadState: Stopped

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft