,System.TimeSpan)} ,System.TimeSpan,System.Reactive.Concurrency.IScheduler)} ,System.IObservable{--1})}
Observable.Sample(IObservable, TimeSpan) method¶
Defined in
Type: Observable
Namespace: System.Reactive.Linq
Assembly: System.Reactive.dll
Applies to
netstandard2.0
Overloads¶
- 1.
public static IObservable<TSource> Sample<TSource>(this IObservable<TSource> source, TimeSpan interval) - 2.
public static IObservable<TSource> Sample<TSource>(this IObservable<TSource> source, TimeSpan interval, IScheduler scheduler) - 3.
public static IObservable<TSource> Sample<TSource, TSample>(this IObservable<TSource> source, IObservable<TSample> sampler)
1. Overload¶
public static IObservable<TSource> Sample<TSource>(this IObservable<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | Source sequence to sample. |
interval | TimeSpan | Interval at which to sample. If this value is equal to TimeSpan.Zero, the scheduler will continuously sample the stream. |
Returns: IObservable
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
| Type | Condition |
|---|---|
| System.ArgumentNullException | source is null. |
| System.ArgumentOutOfRangeException | interval is less than TimeSpan.Zero. |
2. Overload¶
public static IObservable<TSource> Sample<TSource>(this IObservable<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | Source sequence to sample. |
interval | TimeSpan | Interval 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: IObservable
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
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or scheduler is null. |
| System.ArgumentOutOfRangeException | interval is less than TimeSpan.Zero. |
3. Overload¶
public static IObservable<TSource> Sample<TSource, TSample>(this IObservable<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
TSample | The type of the elements in the sampling sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | Source sequence to sample. |
sampler | IObservable | Sampling tick sequence. |
Returns: IObservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or sampler is null. |