The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
Thread::ThreadState Property
.NET Framework (current version)
Gets a value containing the states of the current thread.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Threading::ThreadStateOne 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 |
|---|
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 namespace System; using namespace System::Threading; // ref class ApartmentTest // { // public: static void ThreadMethod() { Thread::Sleep( 1000 ); // } }; int main() { // Thread^ newThread = gcnew Thread( gcnew ThreadStart( &ApartmentTest::ThreadMethod ) ); Thread^ newThread = gcnew Thread( gcnew 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); } // The example displays the following output: // ThreadState: Unstarted // ThreadState: WaitSleepJoin // ThreadState: Stopped
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show:
