I donβt know how to change the existing sampling interval, but what you could do is select at the highest frequency that you need, and then a filter with the Where clause, which uses a variable that you can change.
For example:
static IObservable<T> SampleEvery<T>(this IObservable<T> source, Func<int> multipleProvider) { int counter = 0; Func<T, bool> predicate = ignored => { counter++; if (counter >= multipleProvider()) { counter = 0; } return counter == 0; }; return source.Where(predicate); }
You would call it this way:
// Keep this somewhere you can change it int multiple = 1; eventAsObservable.Sample(TimeSpan.FromSeconds(1)) .SampleEvery(() => multiple) .Timestamp() .Subscribe(x => Console.WriteLine("testing:" + x.Value.EventArgs.str));
Changing the multiple value will now change the effective sampling rate.
This is a pretty ugly hack, but I think it should work.
Jon skeet
source share