Question

My app needs to load a usercontrol in the MainWindow on startup. However the initialization of the usercontrol is slow. (not because of loading business data, I already separate the UI from business layer)

What I want to do is while waiting for the initialization of the usercontrol, a busy indicator will appear and will disappear when the initialization of the usercontrol is finished.

Right now I have a IsBusy property in the MainViewModel and is databind to the busyindicator in the MainWindow.

The child usercontrol is displayed via a contentcontrol.

presenter.Content = new ChildUserControl(); 
//presenter is the contentcontrol in MainWindow

However, how to run both the initialization and the display of busy indicator simultaneously? It seems that I need different threads to handle this issue.

However, running the initialization on a different thread while letting the main UI thread display the busy indicator will not work, since a child control in another thread cannot be placed within its parent control, which in this case is the MainWindow.

Any ideas on that?

Was it helpful?

Solution

I have implemented it myself. Namely I had scenario where we had XPS document loading(it was really slow) and then I had to implement spinner("busy indicator"). But that didn't work because they were on the same thread.

Now Dwayne come up with clever way how to multithread this, and it worked. http://blogs.msdn.com/b/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx

OTHER TIPS

What about displaying the animated loading cursor? Windows already handles the threading on the mouse. I have had this problem before and I implemented my own loading animation on another thread but I had problems with rendering priorities causing the main executing code to be slow unless the mouse cursor was moving on top of the progress dialog. https://stackoverflow.com/a/307020/2247427

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top