title: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created" only occurs the second time form opens
body: <p>The application I am developing is a plugin to an existing application and the first time running the plugin everything works great. However when I open the plugin a second time I get the error:</p>
  
  <p><em>InvalidOperationException was unhandled - Invoke or BeginInvoke cannot be called on a control until the window handle has been created.</em></p>
  
  <p>I understand race conditions and from everything I've read, this error occurs when trying to access a form element before <code>HandleCreated</code> is true, but I cannot figure out why this is happening only the second time I open the plugin.</p>
  
  <p>Here is the plugin code. The error occurs when calling <code>SetProgressBar()</code>:</p>
  
  <pre><code>    private MainForm mainForm;
  
      public void StartPlugin()
      {
          mainForm  = new MainForm (this);
          mainForm .ShowDialog();
      }
  
      public bool GetJoinEnabled()
      {
          mainForm.SetProgressBar(3);
      }
  </code></pre>
  
  <p>Here's my main form:</p>
  
  <pre><code>    private Thread m_JoinThread;
      private JoinPlugin m_Join;
  
      public MainForm(JoinPlugin zig)
      {
          m_Join = zig;
          InitializeComponent();
          m_JoinThread= new Thread(new ThreadStart(GetJoinData));
          m_JoinThread.Start();
      }
  
      private void GetJoinData()
      {
         //Get enable join data
          bool result = m_Join.GetJoinEnabled();
      }
  
      public void SetProgressBar(int value)
      {
          SetProgressCallback del = new SetProgressCallback(SetProgressBarControl);
          this.Invoke(del, value);
      }
  
      private void SetProgressBarControl(int value)
      {
          progressBar.Value = value;
      }
  </code></pre>