title: How to ensure a Windows Form is "fully" closed?
body: <p>I have a form in a Windows form application that I want to display on top of a main form, close it, and then immediately show a dialog box using <code>MessageBox.Show()</code>.  But the first form is still showing when the message box is shown, and it does not disappear until I click OK on the message box.  I tried waiting to show the message box in an event handler for the form's <code>VisibleChanged</code> event and even calling <code>Refresh()</code> on both the form and the main form.  Is there a way I can determine when the first form has fully disappeared before displaying the message box?</p>
  
  <p>Edit:</p>
  
  <p>Here is some code that demonstrates how the forms are being shown.</p>
  
  <pre><code>static class Program
  {
      // The main form is shown like this:
      static void Main()
      {
          Application.Run(new MainForm());
      }
  }
  
  public class Class1 
  {
      // _modalForm is the first form that is displayed that won't fully go away 
      // when it is closed.
      ModalForm _modalForm;
      BackgroundWorker _worker;
  
      public Class1()
      {
          _modalForm = new ModalForm();
          _worker = new BackGroundWorker();
          _worker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted
      }
  
      public void Method1()
      {
          _worker.RunWorkerAsync();
  
          // The first form is shown.
          _modalForm.ShowDialog();
      }
  
  
      // This code runs in the UI thread.         
      void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          _modalForm.VisibleChanged += new EventHandler(_modalForm_visibleChanged);
          _modalForm.Close();
      }
  
      void _modalForm_visibleChanged(object sender, EventArgs e)
      {
          // When the message box is shown, the other form is still visible
          // and remains so until I click OK.
          MessageBox.Show("The other form was just closed.");
  
          // Note:  I originally tried to use the FormClosed event instead of
          // VisibleChanged.  Then I tried Deactivate, in attempt to use an event
          // that occurred later thinking that might do the trick.  VisibleChanged
          // is the latest event that I found.
          // 
      }
  </code></pre>