title: Creating a progress bar that runs on another thread, while keeping calculation in main thread
body: <p>Preface:  <em>I know this is an unusual/improper way to do this.  I can do this with a "real" ShowDialog(), background worker/thread, and so on. I'm not looking for help doing it that way; I am trying to do specifically what I describe here, even if it is ugly.  If this is impossible for X reason, please let me know though.</em></p>
  
  <hr>
  
  <p>I have created a fancy progress dialog for some of our long running operations.  I need to have this dialog shown on a new thread while having processing continue on the calling (UI in most cases) thread.  </p>
  
  <p>This has 3 real requirements:</p>
  
  <ul>
  <li>Prevent user interaction with the calling form (similar to ShowDialog(this))</li>
  <li>Keep the progress dialog above the main window (it can fall behind now)</li>
  <li>Allow the main thread to continue processing</li>
  </ul>
  
  <p>What I have looks like this (and works just fine so far, as far as running goes, except for those issues above):</p>
  
  <pre><code>Using ... ShowNewProgressDialogOnNewThread() ...
        Logic
        UpdateProgress() //static
        Logic
        UpdateProgress() //static, uses Invoke() to call dialog
        ...
  End Using  // destroys the form, etc
  </code></pre>
  
  <p>I have tried a few ways to do this:</p>
  
  <ul>
  <li><strong>ShowDialog</strong>() on <strong>BackgroundWorker</strong> / Thread</li>
  <li><strong>Action.BeginInvoke()</strong> which calls a function </li>
  <li><strong>ProgressForm.BeginInvoke(</strong>... method that calls ShowDialog... )</li>
  <li>Wrapping main form in a class that implements IWin32Window so it can be called cross-threaded and passed to ShowDialog() - this one failed somewhere later one, but at least causes ShowDialog() to not barf immediately.</li>
  </ul>
  
  <p>Any clues or wisdom on how to make this work?</p>
  
  <h2>Solution (For Now)</h2>
  
  <ul>
  <li>The call to EnableWindow is what did what I was looking for.  </li>
  <li>I do not experience any crashes at all</li>
  <li>Changed to use ManualResetEvent</li>
  <li>I set TopMost, because I couldn't always guarantee the form would end up on top otherwise.  Perhaps there is a better way.</li>
  <li>My progress form is like a splash screen (no sizing, no toolbar, etc), perhaps that accounts for the lack of crashes (mentioned in answer)</li>
  <li>Here is <a href="https://stackoverflow.com/questions/648255/how-to-block-winforms-ui-while-background-thread-is-running">another thread on the EnableWindow topic</a> (didn't reference for this fix, tho)</li>
  </ul>