Table of Contents

Class JoinableTask

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
Inheritance
JoinableTask
Derived
Inherited Members

Remarks

For more complete comments please see the JoinableTaskContext.

Properties

IsCompleted

Gets a value indicating whether the async operation represented by this instance has completed, as represented by its Task property's IsCompleted value.

public bool IsCompleted { get; }

Property Value

bool

Task

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

public Task Task { get; }

Property Value

Task

Methods

GetAwaiter()

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

public TaskAwaiter GetAwaiter()

Returns

TaskAwaiter

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 caller is on the Main thread (or is executing within a JoinableTask that has access to the main thread) the caller's access to the Main thread propagates to this JoinableTask so that it may also access the main thread.

public void Join(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

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

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)

Shares any access to the main thread the caller may have 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 JoinAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token that will revert the Join and cause the returned task to complete before the async operation has completed.

Returns

Task

A task that completes after the asynchronous operation completes and the join is reverted.

Remarks

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

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.