title: Object reference not set to an instance of an object in splashform
body: <p>I wanted my program to show a loading message while it checks if the program has connected to a device... but i get an error when i try to close the splashform using the code</p>
  
  <pre><code>SplashForm.CloseForm();
  </code></pre>
  
  <p>the actual splashform code is...</p>
  
  <pre><code>class SplashForm
  {
      //Delegate for cross thread call to close
      private delegate void CloseDelegate();
  
      //The type of form to be displayed as the splash screen.
      private static SplashForm splashForm;
  
      static public void ShowSplashScreen()
      {
          // Make sure it is only launched once.
  
          if (splashForm != null)
              return;
          Thread thread = new Thread(new ThreadStart(SplashForm.ShowForm));
          thread.IsBackground = true;
          thread.SetApartmentState(ApartmentState.STA);
          thread.Start();           
      }
  
      static private void ShowForm()
      {
          splashForm = new SplashForm();
          Application.Run(splashForm);
      }
  
      static public void CloseForm()
      {
          splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
      }
  
      static private void CloseFormInternal()
      {
          splashForm.Close();
      }
  ...
  }
  </code></pre>
  
  <p>in this code... I get a error message as "Object reference not set to an instance of an object" at the line </p>
  
  <pre><code> splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
  </code></pre>
  
  <p>what is the reason and solution?</p>