程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 線程狀態及其轉換

線程狀態及其轉換

編輯:C#入門知識

線程對象使用ThreadState.屬性指示線程狀態。

ThreadState是帶flag特性的枚舉類型對象,因此判斷線程當前的狀態必須用bitmask,作為一個特例,由於Running狀態的bit碼是0,因此,需要用如下方式判斷線程是否處於運行狀態:(myThread.ThreadState & (ThreadState.Stopped | ThreadState.Unstarted)) == 0。

枚舉成員如下:

 

  Member name Description   Running The thread has been started, it is not blocked, and there is no pendingThreadAbortException.   StopRequested The thread is being requested to stop. This is for internal use only.   SuspendRequested The thread is being requested to suspend.   Background The thread is being executed as a background thread, as opposed to a foreground thread. This state is controlled by setting theThread.IsBackground property.   Unstarted The Thread.Start method has not been invoked on the thread.   Stopped The thread has stopped.   WaitSleepJoin The thread is blocked. This could be the result of calling Thread.Sleep orThread.Join, of requesting a lock — for example, by callingMonitor.Enter orMonitor.Wait — or of waiting on a thread synchronization object such asManualResetEvent.   Suspended The thread has been suspended.   AbortRequested The Thread.Abort method has been invoked on the thread, but the thread has not yet received the pendingSystem.Threading.ThreadAbortException that will attempt to terminate it.   Aborted The thread state includes AbortRequested and the thread is now dead, but its state has not yet changed toStopped.

 

狀態轉換圖如下“

\

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved