System.Threading.Tasks 命名空间

System.Threading.Tasks 命名空间提供简化编写并发和异步代码的工作的类型。 The System.Threading.Tasks namespace provides types that simplify the work of writing concurrent and asynchronous code. 主要类型为 Task(表示可以等待和取消的异步操作)和 Task<TResult>(可以返回值的任务)。 The main types are Task which represents an asynchronous operation that can be waited on and cancelled, and Task<TResult>, which is a task that can return a value. TaskFactory 类提供用于创建和启动任务的静态方法,TaskScheduler 类提供默认线程调度基础结构。 The TaskFactory class provides static methods for creating and starting tasks, and the TaskScheduler class provides the default thread scheduling infrastructure.

ConcurrentExclusiveSchedulerPair

提供任务计划程序,其用于执行任务,同时确保并发任务可同时运行,而独占任务从不运行。Provides task schedulers that coordinate to execute tasks while ensuring that concurrent tasks may run concurrently and exclusive tasks never do.

Parallel

提供对并行循环和区域的支持。Provides support for parallel loops and regions.

ParallelLoopState

可使并行循环迭代与其他迭代交互。Enables iterations of parallel loops to interact with other iterations. 此类的实例由 Parallel 类提供给每个循环;不能在你的用户代码中创建实例。An instance of this class is provided by the Parallel class to each loop; you can not create instances in your code.

ParallelOptions

存储用于配置 Parallel 类的方法的操作的选项。Stores options that configure the operation of methods on the Parallel class.

Task

表示一个异步操作。Represents an asynchronous operation.

Task<TResult>

表示一个可以返回值的异步操作。Represents an asynchronous operation that can return a value.

TaskAsyncEnumerableExtensions

提供一组静态方法,用于配置异步可枚举项和可处置项的任务相关行为。Provides a set of static methods for configuring task-related behaviors on asynchronous enumerables and disposables.

TaskCanceledException

表示一个用于告知任务取消的异常。Represents an exception used to communicate task cancellation.

TaskCompletionSource<TResult>

表示未绑定到委托的 Task<TResult> 的制造者方,并通过 Task 属性提供对使用者方的访问。Represents the producer side of a Task<TResult> unbound to a delegate, providing access to the consumer side through the Task property.

TaskExtensions

提供一组用于处理特定类型的 Task 实例的静态方法(在 Visual Basic 中为共享方法)。Provides a set of static (Shared in Visual Basic) methods for working with specific kinds of Task instances.

TaskFactory

提供对创建和计划 Task 对象的支持。Provides support for creating and scheduling Task objects.

TaskFactory<TResult>

提供对创建和计划 Task<TResult> 对象的支持。Provides support for creating and scheduling Task<TResult> objects.

TaskScheduler

表示一个处理将任务排队到线程中的低级工作的对象。Represents an object that handles the low-level work of queuing tasks onto threads.

TaskSchedulerException

表示一个用于告知由 TaskScheduler 计划的某个操作无效的异常。Represents an exception used to communicate an invalid operation by a TaskScheduler.

UnobservedTaskExceptionEventArgs

为在出错的 Task 的异常未观察到时引发的事件提供数据。Provides data for the event that is raised when a faulted Task's exception goes unobserved.

结构

ParallelLoopResult

提供执行 Parallel 循环的完成状态。Provides completion status on the execution of a Parallel loop.

ValueTask

提供异步操作的可等待结果。Provides an awaitable result of an asynchronous operation.

ValueTask<TResult>

提供包装 Task<TResult>TResult(仅使用其中之一)的值类型。Provides a value type that wraps a Task<TResult> and a TResult, only one of which is used.

枚举

TaskContinuationOptions

为通过使用 ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) 方法创建的任务指定行为。Specifies the behavior for a task that is created by using the ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) or ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) method.

TaskCreationOptions

指定可控制任务的创建和执行的可选行为的标志。Specifies flags that control optional behavior for the creation and execution of tasks.

TaskStatus

表示 Task 的生命周期中的当前阶段。Represents the current stage in the lifecycle of a Task.

另请参阅