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

提供一組 static (Visual Basic 中是 Shared) 方法,以處理特定類型的 Task 執行個體。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.

另請參閱