Table of Contents

Class JoinableTask<T>

Namespace
Microsoft.VisualStudio.Threading
Assembly
Microsoft.VisualStudio.Threading.dll

Tracks asynchronous operations and provides the ability to Join those operations to avoid deadlocks while synchronously blocking the Main thread for the operation's completion.

public class JoinableTask<T> : JoinableTask

Type Parameters

T

The type of value returned by the asynchronous operation.

Inheritance
JoinableTask<T>
Inherited Members

Remarks

For more complete comments please see the JoinableTaskContext.

Properties

Task

Gets the asynchronous task that completes when the async operation completes.

public Task<T> Task { get; }

Property Value

Task<T>

Methods

GetAwaiter()

Gets an awaiter that is equivalent to calling JoinAsync(CancellationToken).

public TaskAwaiter<T> GetAwaiter()

Returns

TaskAwaiter<T>

A task whose result is the result of the asynchronous operation.

Join(CancellationToken)

Synchronously blocks the calling thread until the operation has completed. If the calling thread is the Main thread, deadlocks are mitigated.

public T Join(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token that will exit this method before the task is completed.

Returns

T

The result of the asynchronous operation.

Remarks

Any exception thrown by the asynchronous operation is propagated out to the caller of this method.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.

JoinAsync(CancellationToken)

Joins any main thread affinity of the caller with the asynchronous operation to avoid deadlocks in the event that the main thread ultimately synchronously blocks waiting for the operation to complete.

public Task<T> JoinAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token that will exit this method before the task is completed.

Returns

Task<T>

A task that completes after the asynchronous operation completes and the join is reverted, with the result of the operation.

Remarks

Any exception thrown by the asynchronous operation is propagated out to the caller of this method.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.