0

I have a WPF Application and a Login Window using a separate Thread. On my main Thread the Application is loading (PRISM Modules etc.) and reports the progress to my Login Window.

When the Bootstrapper has finished the Login View will be closed and the Application MainWindow will be shown.

To be sure every Background Work or Dispatcher Activity is done I want to call an method before Showing the MainWindow.

Is there any Method to process with all pending Background tasks / Dispatcher queue Items?

Johannes Wanzek
  • 2,825
  • 2
  • 29
  • 47
  • Can you use the ManualResetEvent? – Gayot Fow Apr 17 '14 at 10:10
  • 1
    You might attach a handler to the [DispatcherInactive](http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherhooks.dispatcherinactive.aspx) event of the [Dispatcher.Hooks](http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.hooks.aspx). – Clemens Apr 17 '14 at 10:12

1 Answers1

1

You could check if the dispatcher is idle in order to make sure no operations are present.

To do this you could hook into the dispatcher using Dispatcher.CurrentDispatcher.Hooks

After this you could add an event handler for hooks.DispatcherInactive += DispatcherInactiveHandler

That should tell you if the Dispatcher is currently empty.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321