/// <inheritdoc/> public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { var composite = new CompositeDisposable(2); if (dueTime == TimeSpan.Zero) { if (!Dispatcher.UIThread.CheckAccess()) { var cancellation = new CancellationDisposable(); Dispatcher.UIThread.Post(() => { if (!cancellation.Token.IsCancellationRequested) { composite.Add(action(this, state)); } }, DispatcherPriority.DataBind); composite.Add(cancellation); } else { return(action(this, state)); } } else { composite.Add(DispatcherTimer.RunOnce(() => composite.Add(action(this, state)), dueTime)); } return(composite); }
/// <inheritdoc/> public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { IDisposable PostOnDispatcher() { var composite = new CompositeDisposable(2); var cancellation = new CancellationDisposable(); Dispatcher.UIThread.Post(() => { if (!cancellation.Token.IsCancellationRequested) { composite.Add(action(this, state)); } }, DispatcherPriority.Background); composite.Add(cancellation); return(composite); } if (dueTime == TimeSpan.Zero) { if (!Dispatcher.UIThread.CheckAccess()) { return(PostOnDispatcher()); } else { if (_reentrancyGuard >= MaxReentrantSchedules) { return(PostOnDispatcher()); } try { _reentrancyGuard++; return(action(this, state)); } finally { _reentrancyGuard--; } } } else { var composite = new CompositeDisposable(2); composite.Add(DispatcherTimer.RunOnce(() => composite.Add(action(this, state)), dueTime)); return(composite); } }