How to block the UI during asynchronous operations in WPF

Posted by mcintyre321 on Stack Overflow See other posts from Stack Overflow or by mcintyre321
Published on 2010-03-17T13:14:14Z Indexed on 2010/03/17 13:21 UTC
Read the original article Hit count: 294

We have a WPF app (actually a VSTO WPF app). On certain controls there are multiple elements which, when clicked, load data from a web service and update the UI. Right now, we carry out these web requests synchronously, blocking the UI thread until the response comes back. This prevents the user clicking around the app while the data is loading, potentially putting it into an invalid state to handle the data when it is returned.

Of course the app becomes unresponsive if the request takes a long time. Ideally, we'd like to have the cancel button active during this time, but nothing else. Is there a clever way of doing this, or will we have to switch the requests to execute asynchronously using backgroundworker and write something that disables all the controls apart from the cancel button while a request is in progress?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about asynchronous