Namespace:
System.Threading.Tasks
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True, _ ExternalThreading := True)> _ Public Class TaskCompletionSource(Of TResult) |
C# |
---|
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)] public class TaskCompletionSource<TResult> |
Type Parameters
- TResult
- The type of the result value assocatied with this TaskCompletionSource<(Of <(TResult>)>).
Remarks
It is often the case that a Task<(Of <(TResult>)>) is desired to represent another asynchronous operation. TaskCompletionSource is provided for this purpose. It enables the creation of a task that can be handed out to consumers, and those consumers can use the members of the task as they would any other. However, unlike most tasks, the state of a task created by a TaskCompletionSource is controlled explicitly by the methods on TaskCompletionSource. This enables the completion of the external asynchronous operation to be propagated to the underlying Task. The separation also ensures that consumers are not able to transition the state without access to the corresponding TaskCompletionSource.
All members of TaskCompletionSource<(Of <(TResult>)>) are thread-safe and may be used from multiple threads concurrently.
Inheritance Hierarchy
System.Threading.Tasks..::.TaskCompletionSource<(Of <(TResult>)>)