Bootstrapper causes other UI frozen

Topics: Prism v4 - WPF 4
Jul 17, 2013 at 9:08 AM
Edited Jul 17, 2013 at 9:12 AM
Hi All,

I am using Prism 4.1 and WPF MVVM as my base app platform. I have a login window with a busy indicator control. I am using BackgroundWorker class so that user can see the busy indicator when prism is loading all modules.

code snippets look like below:
var backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += OnBackgroundWorkerDoWork;

public void OnBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
    Bootstrapper bootstrapper = new Bootstrapper();
However, when the bootstrapper is running, the login window is frozen. Why? how to work around this?

I also tried Application.Current.Dispatcher.BeginInvoke to run Bootstrapper but no luck.

Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new LoginDelegate(Login));
Jul 17, 2013 at 8:16 PM

Unfortunately, running the bootstrapper in a background thread is not a trivial task. Basically, there are two main problems you will find when trying to do so:

  • Beside the initialization on the modules, the bootstrapper is also in charge of initializing the shell. Hence, you will need to invoke all logic related to the creation, initialization and activation of the shell to the UI thread (for example, via the Dispatcher.)
  • Usually during their initialization, the modules might need to interact with the with the UI too, for example by adding or registering views to a region. This logic also needs to be invoked in the UI thread.
In my opinion, an easier implementation could be to show a new "window" though a different STA thread and then run the bootstrapper in the main thread normally. In this new "window" can show any information you might need to inform the user that the application is being loaded (using busy indicators, progress bars, etc.)

This approach is similar to the one used to show non-static splash screens in the following thread:
I hope this helps,

Damian Cherubini
Jul 18, 2013 at 1:38 AM
Thanks Damian very much. That's a nice approach, it's working for me!