System.Threading 命名空间
提供支持多线程编程的类和接口。 Provides classes and interfaces that enable multithreaded programming. 除同步线程活动和数据访问的类(Mutex、Monitor、 Interlocked、AutoResetEvent等)之外,此命名空间还包含一个 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. |
EventWaitHandleAcl |
提供了一种特定于 Windows 的扩展方法,用于通过特定的访问控制列表 (ACL) 安全性来创建 EventWaitHandle 对象。Provides a Windows-specific extension method for creating EventWaitHandle objects with specific access control list (ACL) security. |
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 |
提供使公共语言运行时宿主可以参与执行上下文的流动(或移植)的功能。Provides the functionality that allows a common language runtime host to participate in the flow, or migration, of the execution context. |
Interlocked |
为多个线程共享的变量提供原子操作。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. |
MutexAcl |
提供了一种特定于 Windows 的扩展方法,用于通过特定的访问控制列表 (ACL) 安全性来创建 Mutex 对象。Provides a Windows-specific extension method for creating Mutex objects with specific access control list (ACL) security. |
Overlapped |
提供 Win32 |
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. |
SemaphoreAcl |
提供了一种特定于 Windows 的扩展方法,用于通过特定的访问控制列表 (ACL) 安全性来创建 Semaphore 对象。Provides a Windows-specific extension method for creating Semaphore objects with specific access control list (ACL) security. |
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 |
提供特定于 Windows 的扩展方法,用来管理 EventWaitHandleMutex 和 Semaphore 的访问控制列表 (ACL) 安全描述符。Provides Windows-specific extension methods for managing the access control list (ACL) security descriptors for EventWaitHandle, Mutex, and Semaphore. |
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 |
当基础操作系统线程已启动但该线程尚未准备好执行用户代码前,托管线程中出现错误,则会引发异常。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 |
当尝试打开不存在的系统互斥体、信号量或事件等待句柄时引发的异常。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 |
提供针对 wait 句柄使用 safe 句柄的简便方法。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 |
定义实现单个编写器/多个阅读器语义的锁。Defines the lock that implements single-writer/multiple-reader semantics. 这是值类型。This is a value type. |
NativeOverlapped |
提供可从非托管代码查看的显式布局,与 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 | |
EventResetMode |
指示在接收信号后是自动重置 EventWaitHandle 还是手动重置。Indicates 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 |
委托
ContextCallback |
表示要在新的上下文中调用的方法。Represents a method to be called within a new context. |
IOCompletionCallback |
当 I/O 操作在线程池上完成时接收错误代码、字节数和重叠值类型。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 |
表示将要处理 Application 的 ThreadException 事件的方法。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. |