The PleaseWaitService allows a developer to show a please wait message (a.k.a. busy indicator) from a view model.

Available for
WPF / Silverlight / WP7 / WP7 Mango

Test/Emulation service available: yes

Showing
var pleaseWaitService = GetService<IPleaseWaitService>();
pleaseWaitService.Show();

Hiding
var pleaseWaitService = GetService<IPleaseWaitService>();
pleaseWaitService.Hide();

Showing and automatically hide
The PleaseWaitService can automatically hide itself when an action is completed. To use this feature, simply pass a delegate to the Show method and the service will hide the window as soon as the delegate has completed.

var pleaseWaitService = GetService<IPleaseWaitService>();
pleaseWaitService.Show(() => Thread.Sleep(1500));

Changing the status
var pleaseWaitService = GetService<IPleaseWaitService>();
pleaseWaitService.UpdateStatus("new status");

Push/Pop
Sometimes, multiple view models or multiple actions use the service. It's not possible to hide the window when the first action is completed, because the user will still have to wait for the other actions to complete (without a please wait window). To implement this correctly, it is possible to use the Push and Pop methods.

The Push method shows the window if it is not already visible and then increases an internal counter. At the start of each (asynchronous) action, the developer can call the Push method. When the action is completed, the developer calls Pop which will internally decrease the counter. If the counter hits zero (0), the window is automatically hidden.

It is possible to hide the window, even when the internal counter is not yet zero. A call to Hide will reset the counter to zero and thus hide the window.

Last edited Jul 10, 2011 at 12:50 PM by GeertvanHorrik, version 3

Comments

No comments yet.