Setting a Vidyano WPF application in “busy” mode

Today I will show you how you can disable all actions in a WPF application by using something called the IBusyService.


Notifying the application that you are busy performing some logic is needed in some cases. In a traditional application, the UI is automatically locked when you are preforming logic on the UI-thread. This leads to an application that doesn’t respond to user input very fast. Something that can be very frustrating for your users. In order to be able to work around this problem, you want to do as much processing on a different thread as possible. Both the WPF and the HTML5/JS interface make heavy use of this “async” way of working. There is one thing however, that you should be very aware of. When you move all the work off the UI-thread, the UI will become way more responsive, but also available for your users to perform actions. this is something that is not always wanted.

Let me give you an example: You display a list of items in a query. When you click on an item, the item will be opened in a new page. When this opening happens on a background-thread, the user could click on another item in the query. This item will then also being opened. And that is only if the responses come in the same order as the requests, something that is not guaranteed!

If you find yourself in this or any similar case, that you need what we named the ‘IBusyService.’


How to use

Using the IBusyService is very simple. The following sample shows how to use it:

using (ServiceLocator.GetService<IBusyService>().Push())
	var responsePO = ServiceLocator.GetService<IServiceGateway>().ExecuteAction("YourAction",obj.Parent, null, null);

In this simple sample, I used the ServiceLocator to get the IBusyService. Calling Push will push the busy status onto the IBusyService. This client will then automatically disable all actions on the client. Mind that this will not block the UI, simply making sure the user cannot perform any action while the service is busy. Make sure to wrap the Push call inside a using clause, to automatically enable all actions on the UI again. Inside the using you can perform any code you want, including making calls to the Vidyano Service.