共用方式為


AsyncQueue<T>.DequeueAsync(CancellationToken) Method

Definition

Gets a task whose result is the element at the head of the queue.

public System.Threading.Tasks.Task<T> DequeueAsync (System.Threading.CancellationToken cancellationToken = default);
member this.DequeueAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<'T>
Public Function DequeueAsync (Optional cancellationToken As CancellationToken = Nothing) As Task(Of T)

Parameters

cancellationToken
CancellationToken

A token whose cancellation signals lost interest in the item. Cancelling this token does not guarantee that the task will be canceled before it is assigned a resulting element from the head of the queue. It is the responsibility of the caller to ensure after cancellation that either the task is canceled, or it has a result which the caller is responsible for then handling.

Returns

Task<T>

A task whose result is the head element.

Exceptions

Thrown when this instance has an empty queue and Complete() has been called. Also thrown when cancellationToken is canceled before a work item can be dequeued.

Applies to