Skip to content

,System.TimeSpan)} ,System.TimeSpan,System.Reactive.Concurrency.IScheduler)} ,System.IObservable{--1})}

Qbservable.Sample(IQbservable, TimeSpan) method

Defined in

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

Applies to

netstandard2.0

Overloads

  • 1. public static IQbservable<TSource> Sample<TSource>(this IQbservable<TSource> source, TimeSpan interval)
  • 2. public static IQbservable<TSource> Sample<TSource>(this IQbservable<TSource> source, TimeSpan interval, IScheduler scheduler)
  • 3. public static IQbservable<TSource> Sample<TSource, TSample>(this IQbservable<TSource> source, IObservable<TSample> sampler)

1. Overload

public static IQbservable<TSource> Sample<TSource>(this IQbservable<TSource> source, TimeSpan interval)

Summary: Samples the observable sequence at each interval. Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#Source sequence to sample.
intervalTimeSpanInterval at which to sample. If this value is equal to TimeSpan.Zero, the scheduler will continuously sample the stream.

Returns: IQbservable -- Sampled observable sequence.

Remarks

Specifying a TimeSpan.Zero value for interval doesn't guarantee all source sequence elements will be preserved. This is a side-effect of the asynchrony introduced by the scheduler, where the sampling action may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptioninterval is less than TimeSpan.Zero.

2. Overload

public static IQbservable<TSource> Sample<TSource>(this IQbservable<TSource> source, TimeSpan interval, IScheduler scheduler)

Summary: Samples the observable sequence at each interval, using the specified scheduler to run sampling timers. Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
source[IQbservable](#Source sequence to sample.
intervalTimeSpanInterval at which to sample. If this value is equal to TimeSpan.Zero, the scheduler will continuously sample the stream.
scheduler[IScheduler](#Scheduler to run the sampling timer on.

Returns: IQbservable -- Sampled observable sequence.

Remarks

Specifying a TimeSpan.Zero value for interval doesn't guarantee all source sequence elements will be preserved. This is a side-effect of the asynchrony introduced by the scheduler, where the sampling action may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptioninterval is less than TimeSpan.Zero.

3. Overload

public static IQbservable<TSource> Sample<TSource, TSample>(this IQbservable<TSource> source, IObservable<TSample> sampler)

Summary: Samples the source observable sequence using a sampler observable sequence producing sampling ticks. Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.
TSampleThe type of the elements in the sampling sequence.

Parameters

NameTypeDescription
source[IQbservable](#Source sequence to sample.
samplerIObservableSampling tick sequence.

Returns: IQbservable -- Sampled observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or sampler is null.