/// <summary> /// Creates a progress handler with common UI options: updates are sampled on <paramref name="sampleTimeSpan" /> intervals, /// and the <paramref name="handler" /> is executed on the UI thread. This method must be called from the UI thread. /// The UI should already be initialized with the default state; <paramref name="handler" /> is not invoked with an initial value. /// </summary> /// <param name="sampleTimeSpan">The time span interval to sample progress updates.</param> /// <param name="handler">The progress update handler that updates the UI.</param> /// <returns>The disposable observable progress handler.</returns> public static IDisposableProgress <T> CreateForUi(TimeSpan sampleTimeSpan, Action <T> handler) { var uiScheduler = SynchronizationContext.Current ?? new SynchronizationContext(); var progress = new ObservableProgress <T>(new Subject <T>()); var subscription = progress.Sample(sampleTimeSpan).ObserveOn(uiScheduler).Subscribe(handler); return(new ObservableProgressWithSubscription(progress, subscription)); }
public ObservableProgressWithSubscription(ObservableProgress <T> progress, IDisposable subscription) { this.progress = progress; this.subscription = subscription; }