Skip to content

,System.Action{--0})} ,System.Action{--0},System.Threading.CancellationToken)} ,System.Action{--0,System.Int32})} ,System.Action{--0,System.Int32},System.Threading.CancellationToken)}

Observable.ForEachAsync(IObservable, Action) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource> onNext)
  • 2. public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource> onNext, CancellationToken cancellationToken)
  • 3. public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource, int> onNext)
  • 4. public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource, int> onNext, CancellationToken cancellationToken)

1. Overload

public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource> onNext)

Summary: Invokes an action for each element in the observable sequence, and returns a Task object that will get signaled when the sequence terminates.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
onNextActionAction to invoke for each element in the observable sequence.

Returns: Task -- Task that signals the termination of the sequence.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.

2. Overload

public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource> onNext, CancellationToken cancellationToken)

Summary: Invokes an action for each element in the observable sequence, and returns a Task object that will get signaled when the sequence terminates. The loop can be quit prematurely by setting the specified cancellation token.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
onNextActionAction to invoke for each element in the observable sequence.
cancellationTokenCancellationTokenCancellation token used to stop the loop.

Returns: Task -- Task that signals the termination of the sequence.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.

3. Overload

public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource, int> onNext)

Summary: Invokes an action for each element in the observable sequence, incorporating the element's index, and returns a Task object that will get signaled when the sequence terminates.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
onNextActionAction to invoke for each element in the observable sequence.

Returns: Task -- Task that signals the termination of the sequence.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.

4. Overload

public static Task ForEachAsync<TSource>(this IObservable<TSource> source, Action<TSource, int> onNext, CancellationToken cancellationToken)

Summary: Invokes an action for each element in the observable sequence, incorporating the element's index, and returns a Task object that will get signaled when the sequence terminates. The loop can be quit prematurely by setting the specified cancellation token.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
onNextActionAction to invoke for each element in the observable sequence.
cancellationTokenCancellationTokenCancellation token used to stop the loop.

Returns: Task -- Task that signals the termination of the sequence.

Remarks

This operator is especially useful in conjunction with the asynchronous programming features introduced in C# 5.0 and Visual Basic 11.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.