public IDisposable ScheduleTask(TimeSpan timeSpan, Action action) { if (timeSpan == TimeSpan.Zero) { wpf::System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeAsync(action); return(Disposable.Empty); } wpf::System.Windows.Threading.DispatcherTimer timer = new wpf::System.Windows.Threading.DispatcherTimer(); timer.Interval = timeSpan; timer.Tick += (sender, e) => { action(); timer.Stop(); }; timer.Start(); return(new Disposable(timer.Stop)); }
public IDisposable ScheduleTask(TimeSpan timeSpan, Action action) { if (timeSpan == TimeSpan.Zero) { wpf::System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(action); return Disposable.Empty; } wpf::System.Windows.Threading.DispatcherTimer timer = new wpf::System.Windows.Threading.DispatcherTimer(); timer.Interval = timeSpan; timer.Tick += (sender, e) => { action(); timer.Stop(); }; timer.Start(); return new Disposable(timer.Stop); }