title: Making a splash screen
body: <p>The concept of a splash screen doesn't strike me as something that should be so complicated, but I'm having trouble getting the whole splash screen painted.</p>
  
  <p>Let's say I have two <code>System.Windows.Forms.Form</code>s: RealForm and SplashScreen.  The RealForm contains the initial GUI.  During the RealForm's loading process (that is, in the event handler for the <code>Load</code> event), RealForm creates a connection to a database and then tests the connection.  This can take several seconds, so before I do all of this, I try to throw up a splash screen like so:</p>
  
  <pre><code>private void RealForm_Load(object sender, EventArgs e)
  {
      SplashScreen splash = new SplashScreen();
      splash.Show();
      loadAndCheckDatabase();
      splash.Close();
  }
  </code></pre>
  
  <p>The problem is that the splash screen only gets partially drawn and so it doesn't really look like much of a splash screen.  Any idea why?  What should I do?</p>
  
  <p>For bonus points, does anyone know where to find an explanation for all series of events that occur in typical creation, usage, and destruction of forms?  The above problem is probably because I don't understand what order things occur or where to hook into form events.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>
  Close, but not quite: looking for a little more advice.  Here's the current code:</p>
  
  <pre><code>private SplashScreen splash = new SplashScreen();
  
  private void RealForm_Load(object sender, EventArgs e)
  {
  
      splash.Show();
  
      BackgroundWorker worker = new BackgroundWorker();
      worker.DoWork += new DoWorkEventHandler(worker_DoWork);
      worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
           (worker_RunWorkerCompleted);
      worker.RunWorkerAsync();
      this.Visible = false;
  
  }
  
  void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
      splash.Close();
      this.Visible = true;
  }
  
  void worker_DoWork(object sender, DoWorkEventArgs e)
  {
      loadAndCheckDatabase();
  }
  </code></pre>
  
  <p>Unfortunately, the <code>this.Visible = false</code> doesn't do anything, because it is automatically set to <code>true</code> in code that I don't control.  So, to get around this, I put the <code>this.Visible = false</code> into the handler for the form's <code>Shown</code> event.  However, as you can probably guess, you can still see the form for a split second... so this is not really a good solution.</p>
  
  <p>Is there any way to wait on the worker thread while I'm still in the Load handler?</p>