public static void ExecuteWithSpinner(Action work, string message) { SpinnerDialog spinnerDialog = null; DispatcherHelper.CheckBeginInvokeOnUI(() => { spinnerDialog = new SpinnerDialog(); spinnerDialog.txtMessage.Text = message; spinnerDialog.Show(); }); var doneEvent = new AutoResetEvent(false); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { try { work(); } finally { doneEvent.Set(); } }; worker.RunWorkerCompleted += (sender, args) => { DispatcherHelper.CheckBeginInvokeOnUI(() => { doneEvent.WaitOne(); spinnerDialog.Close(); }); }; worker.RunWorkerAsync(); }
private SpinnerDialog DisplaySpinner(Window window) { // Close any open dialogs. DialogHost.CloseDialogCommand.Execute(new object(), null); // Create a new spinner instance and show it on the specifed window. var spinner = new SpinnerDialog(); DialogHostEx.ShowDialog(window, spinner, spinner.DialogHost_DialogOpened); return(spinner); }
private async Task LoadSpinner(Window window, string initialStatus) { // Async wait handle to delay showing the spinner if desired. await Task.Run(() => delayShowWaitHandle.WaitOne(showDelayMS)); // If the wait handle has been set, then the spinner has been // disposed before the delay period has elapsed, so we will // not attempt to display the spinner. if (delayShowWaitHandle.WaitOne(0)) { return; } if (!string.IsNullOrEmpty(currentStatus) && currentStatus != initialStatus) { initialStatus = currentStatus; } spinner = DisplaySpinner(window); spinner.StatusText = initialStatus; }