title: WPF modal progress window
body: <p>I apologize if this question has been answered tons of times, but I can't seem to find an answer that works for me.  I would like to create a modal window that shows various progress messages while my application performs long running tasks.  These tasks are run on a separate thread and I am able to update the text on the progress window at different stages of the process.  The cross-thread communication is all working nicely.  The problem is that I can't get the window to be on top of only other application windows (not every application on the computer), stay on top, prevent interaction with the parent window, and still allow the work to continue.</p>
  
  <p>Here's what I've tried so far:</p>
  
  <p>First, my splash window is a custom class that extends the Window class and has methods to update the message box.  I create a new instance of the splash class early on and Show/Hide it as needed.</p>
  
  <p>In the simplest of cases, I instantiate the window and call <code>.Show()</code> on it:</p>
  
  <pre><code>//from inside my secondary thread
  this._splash.Dispatcher.Invoke(new Action(() =&gt; this._splash.Show());
  
  //Do things
  //update splash text
  //Do more things
  
  //close the splash when done
  this._splash.Dispatcher.Invoke(new Action(() =&gt; this._splash.Hide());
  </code></pre>
  
  <p>This correctly displays the window and continues running my code to handle the initialization tasks, but it allows me to click on the parent window and bring that to the front.</p>
  
  <p>Next I tried disabling the main window and re-enabling later:</p>
  
  <pre><code>Application.Current.Dispatcher.Invoke(new Action(() =&gt; this.MainWindow.IsEnabled = false));
  
  //show splash, do things, etc
  
  Application.Current.Dispatcher.Invoke(new Action(() =&gt; this.MainWindow.IsEnabled = true));
  </code></pre>
  
  <p>This disables all the elements in the window, but I can still click the main window and bring it in front of the splash screen, which is not what I want.</p>
  
  <p>Next I tried using the topmost property on the splash window.  This keeps it in front of everything, and in conjunction with setting the main window IsEnabled property I could prevent interaction, but this makes the splash screen appear in front of EVERYTHING, including other applications.  I don't want that either.  I just want it to be the topmost window within THIS application.</p>
  
  <p>Then I found posts about using <code>.ShowDialog()</code> instead of <code>.Show()</code>.  I tried this, and it correctly showed the dialog and did not allow me to click on the parent window, but calling <code>.ShowDialog()</code> makes the program hang waiting for you to close the dialog before it will continue running code.  This is obviously, not what I want either.  I suppose I could call <code>ShowDialog()</code> on a different thread so that that thread would hang but the thread doing the work would not...is that the recommended method?</p>
  
  <p>I have also considered the possibility of not using a window at all and instead putting a full-sized window element in front of everything else on the page.  This would work except that I have other windows I open and I'd like to be able to use the splash screen when those are open too.  If I used a window element I would have to re-create it on every window and I wouldn't be able to use my handy <code>UpdateSplashText</code> method in my custom splash class.</p>
  
  <p>So this brings me to the question.  What is the right way to handle this?</p>
  
  <p>Thanks for your time and sorry for the long question but details are important :)</p>