/// <summary> /// Executes the action on the UI thread. /// </summary> /// <param name="action">The action to execute.</param> /// <param name="delay">The delay.</param> public static void OnUIThread(this System.Action action, TimeSpan delay) { if (delay.TotalMilliseconds < 0) { throw new ArgumentOutOfRangeException("delay", delay, "Value must be positive"); } Execute.OnUIThread( delegate { DispatcherTimer t = new DispatcherTimer(); t.Interval = delay; t.Tick += delegate { t.Stop(); action(); }; t.Start(); }); }
void Closing(object sender, CancelEventArgs e) { if (e.Cancel) { return; } var guard = (IGuardClose)model; if (actuallyClosing) { actuallyClosing = false; return; } bool runningAsync = false, shouldEnd = false; guard.CanClose(canClose => { Execute.OnUIThread(() => { if (runningAsync && canClose) { actuallyClosing = true; view.Close(); } else { e.Cancel = !canClose; } shouldEnd = true; }); }); if (shouldEnd) { return; } runningAsync = e.Cancel = true; }
/// <summary> /// Clears the items contained by the collection. /// </summary> protected override sealed void ClearItems() { Execute.OnUIThread(ClearItemsBase); }
/// <summary> /// Removes the item at the specified position. /// </summary> /// <param name = "index">The position used to identify the item to remove.</param> protected override sealed void RemoveItem(int index) { Execute.OnUIThread(() => RemoveItemBase(index)); }
/// <summary> /// Sets the item at the specified position. /// </summary> /// <param name = "index">The index to set the item at.</param> /// <param name = "item">The item to set.</param> protected override sealed void SetItem(int index, T item) { Execute.OnUIThread(() => SetItemBase(index, item)); }
/// <summary> /// Moves the item within the collection. /// </summary> /// <param name="oldIndex">The old position of the item.</param> /// <param name="newIndex">The new position of the item.</param> protected sealed override void MoveItem(int oldIndex, int newIndex) { Execute.OnUIThread(() => MoveItemBase(oldIndex, newIndex)); }