Show / Hide Table of Contents

Class AsyncBridge

Allows to turn WaitHandle and CancellationToken into task.

Inheritance
object
AsyncBridge
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public static class AsyncBridge

Properties

View Source

MaxPoolSize

Gets or sets the capacity of the internal pool used to create awaitable tasks returned from the public methods in this class.

Declaration
public static int MaxPoolSize { get; set; }
Property Value
Type Description
int

Methods

View Source

AsCancellationToken(Task)

Returns a cancellation token that gets signaled when the task completes.

Declaration
public static CancellationToken AsCancellationToken(this Task task)
Parameters
Type Name Description
Task task

The task to observe.

Returns
Type Description
CancellationToken

The token that represents completion state of the task.

Exceptions
Type Condition
ArgumentNullException

task is null.

View Source

AsCancellationToken(Task, out Func<bool>)

Returns a cancellation token that gets signaled when the task completes.

Declaration
public static CancellationToken AsCancellationToken(this Task task, out Func<bool> disposeTokenSource)
Parameters
Type Name Description
Task task

The task to observe.

Func<bool> disposeTokenSource

A delegate that can be used to destroy the source of the returned token if no longer needed. It returns true if token was not canceled by the task; otherwise, false.

Returns
Type Description
CancellationToken

The token that represents completion state of the task.

Exceptions
Type Condition
ArgumentNullException

task is null.

View Source

WaitAsync(CancellationToken, bool)

Obtains a task that can be used to await token cancellation.

Declaration
public static ValueTask WaitAsync(this CancellationToken token, bool completeAsCanceled = false)
Parameters
Type Name Description
CancellationToken token

The token to be converted into task.

bool completeAsCanceled

true to complete task in Canceled state; false to complete task in RanToCompletion state.

Returns
Type Description
ValueTask

A task representing token state.

Exceptions
Type Condition
ArgumentException

token doesn't support cancellation.

View Source

WaitAsync(WaitHandle, CancellationToken)

Obtains a task that can be used to await handle completion.

Declaration
public static ValueTask WaitAsync(this WaitHandle handle, CancellationToken token = default)
Parameters
Type Name Description
WaitHandle handle

The handle to await.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask

The task that will be completed .

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

View Source

WaitAsync(WaitHandle, TimeSpan, CancellationToken)

Obtains a task that can be used to await handle completion.

Declaration
public static ValueTask<bool> WaitAsync(this WaitHandle handle, TimeSpan timeout, CancellationToken token = default)
Parameters
Type Name Description
WaitHandle handle

The handle to await.

TimeSpan timeout

The timeout used to await completion.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<bool>

true if handle is signaled; otherwise, false if timeout occurred.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾