次の方法で共有


Thread States 

The ThreadState property provides information about the status of a thread. Because threads can be in more than one state at any given time, the value stored in ThreadState can be a combination of the values in the ThreadState enumeration. For example, if a thread is blocked on a call to Wait, and another thread calls the Abort method on that same thread, the thread is in both the WaitSleepJoin and the AbortRequested state at the same time.

Changing Thread States

Once a thread has started, you can call its methods to change its state. For example, you can cause a thread to pause for a fixed number of milliseconds by calling System.Threading.Thread.Sleep(System.Int32). The Sleep method takes as a parameter a time-out, which is the number of milliseconds that the thread remains blocked.

Calling Sleep with the argument Infinite causes a thread to sleep until it is interrupted by another thread that calls Interrupt. The Interrupt method wakes the destination thread out of any wait state it may be in and causes an exception to be raised.

You can also pause a thread by calling Suspend. When a thread calls Suspend on itself, the call blocks until another thread resumes it by calling Resume. When a thread calls Suspend on another thread, the call is non-blocking and causes the other thread to pause. Calling Resume breaks another thread out of its suspended state and causes it to resume execution. Unlike Sleep, Suspend does not immediately stop a thread; the suspended thread does not pause until the common language runtime determines that it has reached a safe point.

The Abort method stops a running thread by raising a ThreadAbortException exception that causes the thread to die.

See Thread for detailed information about these methods.

See Also

Reference

SyncLock Statement
System.Threading

Concepts

Multithreaded Applications
Thread Synchronization
Parameters and Return Values for Multithreaded Procedures
Multithreading with Forms and Controls
Delegates and the AddressOf Operator

Other Resources

Multithreading in Components