AsyncEnumerable<TResult>.ForEachAsync Method

Definition

Asynchronously enumerates the query results and performs the specified action on each element.

public System.Threading.Tasks.Task ForEachAsync (Action<TResult> action, System.Threading.CancellationToken cancellationToken = default);
member this.ForEachAsync : Action<'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ForEachAsync (action As Action(Of TResult), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

action
Action<TResult>

The action to perform on each element.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

A task that represents the asynchronous operation.

Remarks

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

Applies to