System.Threading 命名空間

System.Threading 命名空間提供能夠啟用多執行緒程式設計功能的類別和介面。 The System.Threading namespace provides classes and interfaces that enable multithreaded programming. 除了用來同步處理執行緒活動和資料存取的類別 (MutexMonitorInterlockedAutoResetEvent 等) 之外,這個命名空間還包含能讓您使用系統提供的執行緒集區的 ThreadPool 類別,以及能在執行緒集區執行緒上執行回呼方法的 Timer 類別。 In addition to classes for synchronizing thread activities and access to data (Mutex, Monitor, Interlocked, AutoResetEvent, and so on), this namespace includes a ThreadPool class that allows you to use a pool of system-supplied threads, and a Timer class that executes callback methods on thread pool threads.

類別

AbandonedMutexException

當一個執行緒取得另一個執行緒已放棄,但是結束時並未釋放的 Mutex 物件時,所擲回的例外狀況。The exception that is thrown when one thread acquires a Mutex object that another thread has abandoned by exiting without releasing it.

AsyncLocal<T>

表示對於指定的非同步控制流程為本機的環境資料,例如非同步方法。Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method.

AutoResetEvent

代表執行緒同步處理事件會在發出訊號時,釋出一個等候執行緒之後,就自動重設。Represents a thread synchronization event that, when signaled, resets automatically after releasing a single waiting thread. 這個類別無法被繼承。This class cannot be inherited.

Barrier

允許多項工作在多個階段中以平行方式來合作處理某個演算法。Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases.

BarrierPostPhaseException

Barrier 的後續階段動作失敗時所擲回例外狀況。The exception that is thrown when the post-phase action of a Barrier fails.

CancellationTokenSource

CancellationToken 發出訊號,表示應該將它取消。Signals to a CancellationToken that it should be canceled.

CompressedStack

提供用來在目前執行緒上設定及擷取壓縮堆疊的方法。Provides methods for setting and capturing the compressed stack on the current thread. 這個類別無法被繼承。This class cannot be inherited.

CountdownEvent

代表當計數到達零時收到訊號的同步處理原始物件。Represents a synchronization primitive that is signaled when its count reaches zero.

EventWaitHandle

表示執行緒同步處理事件。Represents a thread synchronization event.

ExecutionContext

管理目前執行緒的執行內容。Manages the execution context for the current thread. 這個類別無法被繼承。This class cannot be inherited.

HostExecutionContext

在執行緒之間封裝及散佈主應用程式執行內容。Encapsulates and propagates the host execution context across threads.

HostExecutionContextManager

提供功能,讓 Common Language Runtime 主機可以參與執行內容的流動或移轉。Provides the functionality that allows a common language runtime host to participate in the flow, or migration, of the execution context.

Interlocked

為多重執行緒共用的變數提供不可部分完成的作業 (Atomic Operation)。Provides atomic operations for variables that are shared by multiple threads.

LazyInitializer

提供延遲初始化常式。Provides lazy initialization routines.

LockRecursionException

當遞迴進入鎖定與鎖定的遞迴原則不相符時,擲回的例外狀況。The exception that is thrown when recursive entry into a lock is not compatible with the recursion policy for the lock.

ManualResetEvent

表示執行緒同步處理事件,收到訊號時,必須手動重設。Represents a thread synchronization event that, when signaled, must be reset manually. 這個類別無法被繼承。This class cannot be inherited.

ManualResetEventSlim

表示執行緒同步處理事件,收到訊號時,必須手動重設。Represents a thread synchronization event that, when signaled, must be reset manually. 此類別是 ManualResetEvent 的輕量型替代方案。This class is a lightweight alternative to ManualResetEvent.

Monitor

提供一套機制,同步處理物件的存取。Provides a mechanism that synchronizes access to objects.

Mutex

同步處理原始物件,該物件也可用於進行處理序之間的同步處理。A synchronization primitive that can also be used for interprocess synchronization.

Overlapped

提供受管理的 Win32 OVERLAPPED 結構表示法,包括從 Overlapped 執行個體傳送資訊到 NativeOverlapped 結構的方法。Provides a managed representation of a Win32 OVERLAPPED structure, including methods to transfer information from an Overlapped instance to a NativeOverlapped structure.

PreAllocatedOverlapped

代表原生重疊 I/O 作業的預先配置狀態。Represents pre-allocated state for native overlapped I/O operations.

ReaderWriterLock

定義鎖定,它支援單一寫入器和多重讀取器。Defines a lock that supports single writers and multiple readers.

ReaderWriterLockSlim

代表鎖定,用來管理資源存取,允許多個執行緒的讀取權限或獨佔寫入權限。Represents a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing.

RegisteredWaitHandle

代表呼叫 RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean) 時已經登錄的控制代碼。Represents a handle that has been registered when calling RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean). 這個類別無法被繼承。This class cannot be inherited.

Semaphore

限制可以同時存取資源或資源集區的執行緒數目。Limits the number of threads that can access a resource or pool of resources concurrently.

SemaphoreFullException

在已經達到最大計數的號誌上呼叫 Release 方法時,所擲回的例外狀況。The exception that is thrown when the Release method is called on a semaphore whose count is already at the maximum.

SemaphoreSlim

代表 Semaphore 的輕量型替代品,限制可同時存取一項資源或資源集區的執行緒數目。Represents a lightweight alternative to Semaphore that limits the number of threads that can access a resource or pool of resources concurrently.

SynchronizationContext

提供在各種同步處理模式中散佈同步處理內容的基本功能。Provides the basic functionality for propagating a synchronization context in various synchronization models.

SynchronizationLockException

方法要求呼叫端擁有指定 Monitor 的鎖定,但是不擁有鎖定的呼叫端叫用方法時所擲回的例外狀況。The exception that is thrown when a method requires the caller to own the lock on a given Monitor, and the method is invoked by a caller that does not own that lock.

Thread

可建立和控制執行緒,設定執行緒的優先權,並取得它的狀態。Creates and controls a thread, sets its priority, and gets its status.

ThreadAbortException

Abort(Object) 方法呼叫時所擲回的例外狀況。The exception that is thrown when a call is made to the Abort(Object) method. 這個類別無法被繼承。This class cannot be inherited.

ThreadExceptionEventArgs

提供 ThreadException 事件的資料。Provides data for the ThreadException event.

ThreadingAclExtensions
ThreadInterruptedException

Thread 處於等候狀態時被插斷而擲回的例外狀況。The exception that is thrown when a Thread is interrupted while it is in a waiting state.

ThreadLocal<T>

提供資料的執行緒區域儲存區。Provides thread-local storage of data.

ThreadPool

提供執行緒的集區,可用來執行工作、張貼工作項目、處理非同步 I/O、代表其他執行緒等候,以及處理計時器。Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.

ThreadPoolBoundHandle

表示 I/O 控制代碼,繫結至系統執行緒集區,並讓低階元件接收非同步 I/O 作業的通知。Represents an I/O handle that is bound to the system thread pool and enables low-level components to receive notifications for asynchronous I/O operations.

ThreadStartException

當基礎作業系統執行緒已經啟動,但此執行緒還沒準備好執行使用者程式碼之前,如果 Managed 執行緒內有任何錯誤發生,就會擲回這個例外狀況。The exception that is thrown when a failure occurs in a managed thread after the underlying operating system thread has been started, but before the thread is ready to execute user code.

ThreadStateException

Thread 對於方法的呼叫來說處於無效 ThreadState 時所擲回的例外狀況。The exception that is thrown when a Thread is in an invalid ThreadState for the method call.

Timeout

包含會指定無限逾時間隔的常數。Contains constants that specify infinite time-out intervals. 這個類別無法被繼承。This class cannot be inherited.

Timer

提供一套機制,可於指定間隔在執行緒集區執行緒上執行方法。Provides a mechanism for executing a method on a thread pool thread at specified intervals. 這個類別無法被繼承。This class cannot be inherited.

Volatile

包含用於執行動態記憶體作業的方法。Contains methods for performing volatile memory operations.

WaitHandle

將等候共用資源獨佔存取權限的特定作業系統物件封裝起來。Encapsulates operating system-specific objects that wait for exclusive access to shared resources.

WaitHandleCannotBeOpenedException

嘗試開啟不存在的系統 Mutex、旗號或事件等候控制代碼時所擲回的例外狀況。The exception that is thrown when an attempt is made to open a system mutex, semaphore, or event wait handle that does not exist.

WaitHandleExtensions

提供便利的方法來使用等候控制代碼的安全控制代碼。Provides convenience methods to for working with a safe handle for a wait handle.

結構

AsyncFlowControl

提供功能,以還原執行緒間執行內容的移轉或流量。Provides the functionality to restore the migration, or flow, of the execution context between threads.

AsyncLocalValueChangedArgs<T>

會提供資料變更資訊給 AsyncLocal<T> 執行個體的的類別,該執行個體會註冊變更告知。The class that provides data change information to AsyncLocal<T> instances that register for change notifications.

CancellationToken

傳播通知,表示應該取消作業。Propagates notification that operations should be canceled.

CancellationTokenRegistration

表示已向 CancellationToken 登錄的回呼委派。Represents a callback delegate that has been registered with a CancellationToken.

LockCookie

定義出實作單一寫入器/多重讀取器 (Reader) 語意 (Semantics) 的鎖定。Defines the lock that implements single-writer/multiple-reader semantics. 屬於一種實值型別 (Value Type)。This is a value type.

NativeOverlapped

提供明確配置,這套配置從 Unmanaged 程式碼可以看出,並且配置和 Win32 OVERLAPPED 結構相同,結尾還外加有保留欄位。Provides an explicit layout that is visible from unmanaged code and that will have the same layout as the Win32 OVERLAPPED structure with additional reserved fields at the end.

SpinLock

提供互斥鎖定基本作業,在這個作業中,嘗試取得鎖定的執行緒會用迴圈方式等候,並重複檢查,直到鎖定可用為止。Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available.

SpinWait

提供微調式等候支援。Provides support for spin-based waiting.

介面

IThreadPoolWorkItem

表示可由 ThreadPool 執行的工作項目。Represents a work item that can be executed by the ThreadPool.

列舉

ApartmentState

指定 Thread 的 Apartment 狀態。Specifies the apartment state of a Thread.

EventResetMode

表示收到信號之後,是否會自動或手動重設 EventWaitHandleIndicates whether an EventWaitHandle is reset automatically or manually after receiving a signal.

LazyThreadSafetyMode

指定 Lazy<T> 執行個體如何同步處理多個執行緒進行的存取。Specifies how a Lazy<T> instance synchronizes access among multiple threads.

LockRecursionPolicy

指定相同的執行緒是否可以多次進入鎖定。Specifies whether a lock can be entered multiple times by the same thread.

ThreadPriority

指定 Thread 的排程優先權。Specifies the scheduling priority of a Thread.

ThreadState

指定 Thread 的執行狀態。Specifies the execution states of a Thread.

委派

ContextCallback

表示要在新內容裡面呼叫的方法。Represents a method to be called within a new context.

IOCompletionCallback

當執行緒集區的 I/O 作業完成時,可接收錯誤碼、位元組的數目和重疊的實值型別 (Value Type)。Receives the error code, number of bytes, and overlapped value type when an I/O operation completes on the thread pool.

ParameterizedThreadStart

代表在 Thread 上執行的方法。Represents the method that executes on a Thread.

SendOrPostCallback

表示要將訊息分派至同步處理內容時,所要呼叫的方法。Represents a method to be called when a message is to be dispatched to a synchronization context.

ThreadExceptionEventHandler

代表將處理 ApplicationThreadException 事件之方法。Represents the method that will handle the ThreadException event of an Application.

ThreadStart

代表在 Thread 上執行的方法。Represents the method that executes on a Thread.

TimerCallback

表示處理來自 Timer 的呼叫的方法。Represents the method that handles calls from a Timer.

WaitCallback

表示執行緒集區執行緒執行的回呼方法。Represents a callback method to be executed by a thread pool thread.

WaitOrTimerCallback

表示 WaitHandle 收到信號或逾時時呼叫的方法。Represents a method to be called when a WaitHandle is signaled or times out.