C# Thread class
C# Thread class is found in the System.Threading namespace, to facilitate properties and methods to create and control threads.
C# Thread Properties:
The most common properties of the Thread class are listed below:
Property | Uses |
CurrentThread | To get the instance of currently running thread. |
IsAlive | To determine whether the current thread is alive or not to find the execution status of the thread. |
IsBackground | To retrieve or set the value whether current thread is in background or not. |
ManagedThreadId | To retrieve a unique id for the current managed thread. |
Name | To retrieve or to set the name of the current thread. |
Priority | To retrieve or to set the priority of the current thread. |
ThreadState | To get a value representing the thread state. |
C# Thread Methods:
The most common methods of the Thread class are listed below:
Method | Uses |
Abort() | To terminate the thread and to raise the ThreadAbortException exception. |
Interrupt() | To interrupt a thread which is in WaitSleepJoin state. |
Join() | To block all the calling threads until this thread terminates. |
ResetAbort() | To cancel the Abort request for the current thread. |
Resume() | To resume the suspended thread. It is obsolete. |
Sleep(Int32) | To suspend the current thread for the specified milliseconds. |
Start() | To modify the current state of the thread to Runnable. |
Suspend() | To suspend the current thread if it is not suspended. It is obsolete. |
Yield() | To yield the execution of current thread to another thread. |