示例#1
0
        /// <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>
        /// <param name="scheduler">The scheduler to inject into the <c>Sample</c> operator.</param>
        public static IDisposableProgress <T> CreateForUi(TimeSpan sampleTimeSpan, Action <T> handler, IScheduler scheduler)
        {
            var uiScheduler  = SynchronizationContext.Current ?? new SynchronizationContext();
            var progress     = new ObservableProgress <T>(new Subject <T>());
            var subscription = progress.Sample(sampleTimeSpan, scheduler).ObserveOn(uiScheduler).Subscribe(handler);

            return(new ObservableProgressWithSubscription(progress, subscription));
        }
示例#2
0
 public ObservableProgressWithSubscription(ObservableProgress <T> progress, IDisposable subscription)
 {
     _progress     = progress;
     _subscription = subscription;
 }