Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a modal dialog on a non-UI thread

I'm writing a simple data UI using standard .Net databinding to a typed DataSet from SQL Server.

I have a reload button which calls Fill on all of the DataAdapters to get new data from the database (in case another user changed the data).

This takes some time, during which the UI is frozen. It must be run on the UI thread or the databinding event handlers throw cross-thread exceptions.

I'd like to show a modal "Please Wait" dialog on a background thread (so that it can be animated) while the UI thread connects to the database.

How can I show a modal dialog box on the non-UI thread?


EDIT: I'm aware that best practice is to run the operation in the background, but I can't do that because of the databinding events.

like image 215
SLaks Avatar asked Nov 08 '09 19:11

SLaks


1 Answers

You should do the opposite. Run your long-running process on a background thread and leave the UI thread free to respond to the user actions.

If you want to block any user actions while it is processing you have a number of options, including modal dialogs. Once the background thread completes processing you can inform the main thread about the outcome

like image 150
mfeingold Avatar answered Sep 18 '22 13:09

mfeingold