Skip to content

04.Wait Dialog

eiadxp edited this page May 20, 2018 · 6 revisions

Wait Dialog

You can show a dialog with wait control inside it (by default it is a progress bar but you can change it!) using one of DialogHelper.ShowWait() method overloads. The parameters are:

parent:

The ContentControl that will display the dialog. If you use an overload that does not contain this parameter or if you set its value to null the application main window will be used via Application.Current.MainWindow.

title:

A string displayed in the title bar.

content:

Content displayed above the waiting control.

waitControl:

By default this is a ProgressBar with its IsIndeterminate property set to 'true'. You can provide any UIElement to be used as waiting control.

buttons:

Dialog buttons to be displayed. By default no buttons displayed.

waitingAction:

This action will be executed in the same calling thread and the dialog will be closed when the action finish and return back. This may block the calling thread.

waitingTask:

This task will be executed on different thread and when finished the dialog will be closed, and it will not block the calling thread.

autoStartTask:

Indicate weather the waitingTask should be started after showing the dialog (if true) or the task will be started manually out side the ShowWait() methods (if false). In both cases a continuation task (that will close the dialog) will be created.

The good news is that all DialogHelper methods are thread safe and can be accessed from any thread. This gives us two way to create a waiting dialog and do heavy tasks in the background then close the dialog when we finish the task:

  1. The use an overload of DialogHelper.ShowWait() that takes wiatAction parameter like:
        Task.Run(() => this.ShowWait(() => System.Threading.Thread.Sleep(10000)));
  1. Via an overload that takes waitTask parameter like:
        this.ShowWait(Task.Run(() => System.Threading.Thread.Sleep(10000)));
Clone this wiki locally