private void SetTimeout(TimeSpan delay, Action action) { _timer?.Stop(); _timer = new System.Timers.Timer { AutoReset = false, Interval = delay.TotalMilliseconds }; _timer.Elapsed += (sender, e) => ApplicationDispatcher.BeginInvoke(action); _timer.Start(); }
private void DoButton3Proc() { try { ApplicationDispatcher.BeginInvoke(() => OutputText.Value = "Action 3 background."); // continue the long operation asynchronous. Thread.Sleep(5000); } finally { BusyManager.Instance.EndAsync(Button3Action); ApplicationDispatcher.BeginInvoke(() => OutputText.Value = "Action 3 done."); } }
public void NotifyCollectionChanged() { //OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); if (_lastDispatcherOperation != null) { //Pending: The operation is pending and is still in the System.Windows.Threading.Dispatcher queue. if (_lastDispatcherOperation.Status == DispatcherOperationStatus.Pending) { return; } } _lastDispatcherOperation = ApplicationDispatcher.BeginInvoke(DispatcherPriority.Background, OnCollectionChanged, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
public static void ContinueWithUIDispatcher(this Task task, Action<Task> continuationAction) { task.ContinueWith(task1 => { ApplicationDispatcher.BeginInvoke(continuationAction, task1); }); }