📜  C#线程类

📅  最后修改于: 2020-10-31 10:49:54             🧑  作者: Mango

C#线程类

C#Thread类提供创建和控制线程的属性和方法。在System.Threading命名空间中找到它。

C#线程属性

下面列出了Thread类的重要属性:

Property Description
CurrentThread returns the instance of currently running thread.
IsAlive checks whether the current thread is alive or not. It is used to find the execution status of the thread.
IsBackground is used to get or set value whether current thread is in background or not.
ManagedThreadId is used to get unique id for the current managed thread.
Name is used to get or set the name of the current thread.
Priority is used to get or set the priority of the current thread.
ThreadState is used to return a value representing the thread state.

C#线程方法

下面列出了Thread类的重要方法:

Method Description
Abort() is used to terminate the thread. It raises ThreadAbortException.
Interrupt() is used to interrupt a thread which is in WaitSleepJoin state.
Join() is used to block all the calling threads until this thread terminates.
ResetAbort() is used to cancel the Abort request for the current thread.
Resume() is used to resume the suspended thread. It is obselete.
Sleep(Int32) is used to suspend the current thread for the specified milliseconds.
Start() changes the current state of the thread to Runnable.
Suspend() suspends the current thread if it is not suspended. It is obselete.
Yield() is used to yield the execution of current thread to another thread.