Skip to content

)} ,System.Action{--0})} ,System.Action{--0},System.Action{System.Exception})} ,System.Action{--0},System.Action)} ,System.Action{--0},System.Action{System.Exception},System.Action)} ,System.IObserver{--0},System.Threading.CancellationToken)} ,System.Threading.CancellationToken)} ,System.Action{--0},System.Threading.CancellationToken)} ,System.Action{--0},System.Action{System.Exception},System.Threading.CancellationToken)} ,System.Action{--0},System.Action,System.Threading.CancellationToken)} ,System.Action{--0},System.Action{System.Exception},System.Action,System.Threading.CancellationToken)}

ObservableExtensions.Subscribe(IObservable) method

Defined in

Type: ObservableExtensions Namespace: System Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IDisposable Subscribe<T>(this IObservable<T> source)
  • 2. public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext)
  • 3. public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError)
  • 4. public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action onCompleted)
  • 5. public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted)
  • 6. public static void Subscribe<T>(this IObservable<T> source, IObserver<T> observer, CancellationToken token)
  • 7. public static void Subscribe<T>(this IObservable<T> source, CancellationToken token)
  • 8. public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, CancellationToken token)
  • 9. public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, CancellationToken token)
  • 10. public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action onCompleted, CancellationToken token)
  • 11. public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted, CancellationToken token)

1. Overload

public static IDisposable Subscribe<T>(this IObservable<T> source)

Summary: Subscribes to the observable sequence without specifying any handlers. This method can be used to evaluate the observable sequence for its side-effects only.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.

Returns: IDisposable -- IDisposable object used to unsubscribe from the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.

2. Overload

public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext)

Summary: Subscribes an element handler to an observable sequence.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

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

Returns: IDisposable -- IDisposable object used to unsubscribe from the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.

3. Overload

public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError)

Summary: Subscribes an element handler and an exception handler to an observable sequence.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onErrorActionAction to invoke upon exceptional termination of the observable sequence.

Returns: IDisposable -- IDisposable object used to unsubscribe from the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onError is null.

4. Overload

public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action onCompleted)

Summary: Subscribes an element handler and a completion handler to an observable sequence.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onCompletedActionAction to invoke upon graceful termination of the observable sequence.

Returns: IDisposable -- IDisposable object used to unsubscribe from the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onCompleted is null.

5. Overload

public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted)

Summary: Subscribes an element handler, an exception handler, and a completion handler to an observable sequence.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onErrorActionAction to invoke upon exceptional termination of the observable sequence.
onCompletedActionAction to invoke upon graceful termination of the observable sequence.

Returns: IDisposable -- IDisposable object used to unsubscribe from the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onError or onCompleted is null.

6. Overload

public static void Subscribe<T>(this IObservable<T> source, IObserver<T> observer, CancellationToken token)

Summary: Subscribes an observer to an observable sequence, using a CancellationToken to support unsubscription.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
observerIObserverObserver to subscribe to the sequence.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or observer is null.

7. Overload

public static void Subscribe<T>(this IObservable<T> source, CancellationToken token)

Summary: Subscribes to the observable sequence without specifying any handlers, using a CancellationToken to support unsubscription. This method can be used to evaluate the observable sequence for its side-effects only.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.

8. Overload

public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, CancellationToken token)

Summary: Subscribes an element handler to an observable sequence, using a CancellationToken to support unsubscription.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext is null.

9. Overload

public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, CancellationToken token)

Summary: Subscribes an element handler and an exception handler to an observable sequence, using a CancellationToken to support unsubscription.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onErrorActionAction to invoke upon exceptional termination of the observable sequence.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onError is null.

10. Overload

public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action onCompleted, CancellationToken token)

Summary: Subscribes an element handler and a completion handler to an observable sequence, using a CancellationToken to support unsubscription.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onCompletedActionAction to invoke upon graceful termination of the observable sequence.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onCompleted is null.

11. Overload

public static void Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted, CancellationToken token)

Summary: Subscribes an element handler, an exception handler, and a completion handler to an observable sequence, using a CancellationToken to support unsubscription.

Type parameters

NameDescription
TThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableObservable sequence to subscribe to.
onNextActionAction to invoke for each element in the observable sequence.
onErrorActionAction to invoke upon exceptional termination of the observable sequence.
onCompletedActionAction to invoke upon graceful termination of the observable sequence.
tokenCancellationTokenCancellationToken that can be signaled to unsubscribe from the source sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or onNext or onError or onCompleted is null.