Skip to content

,System.Reactive.Concurrency.IScheduler)} ,System.Threading.SynchronizationContext)}

Synchronization.SubscribeOn(IObservable, IScheduler) method

Defined in

Type: Synchronization Namespace: System.Reactive.Concurrency Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<TSource> SubscribeOn<TSource>(IObservable<TSource> source, IScheduler scheduler)
  • 2. public static IObservable<TSource> SubscribeOn<TSource>(IObservable<TSource> source, SynchronizationContext context)

1. Overload

public static IObservable<TSource> SubscribeOn<TSource>(IObservable<TSource> source, IScheduler scheduler)

Summary: Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
scheduler[IScheduler](#Scheduler to perform subscription and unsubscription actions on.

Returns: IObservable -- The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.

Remarks

Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified scheduler. In order to invoke observer callbacks on the specified scheduler, e.g. to offload callback processing to a dedicated thread, use ObserveOn.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.

2. Overload

public static IObservable<TSource> SubscribeOn<TSource>(IObservable<TSource> source, SynchronizationContext context)

Summary: Wraps the source sequence in order to run its subscription and unsubscription logic on the specified synchronization context.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence.
contextSynchronizationContextSynchronization context to perform subscription and unsubscription actions on.

Returns: IObservable -- The source sequence whose subscriptions and unsubscriptions happen on the specified synchronization context.

Remarks

Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified synchronization context. In order to invoke observer callbacks on the specified synchronization context, e.g. to post callbacks to a UI thread represented by the synchronization context, use ObserveOn.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or context is null.