title: c# cross-thread error with UserControls
body: <p>Here is my situation:</p>
  
  <p>I instantiated a c# usercontrol on a main thread, but it is not added to the form. </p>
  
  <pre><code>//global declaration
  usercontrol1 datacontrol;
  
   constructor()
  {
  .......
       datacontrol = new usercontrol1();
  ........
  }
  </code></pre>
  
  <p>I then have an asyhcnronous background thread that fires an event that is handled by the instantiated datacontrol. The event handler has a:</p>
  
  <pre><code>if(InvokeRequired){BeginInvoke(..);}
  </code></pre>
  
  <p>This should prevent any cross-threaded calls from being made. However when this gets called InvokeRequired is false so the handler is not invoked on the correct thread. So in the handler when I attemped a this.labelname.text ="blah" a cross-thread exception is thrown.</p>
  
  <p>However if I add the control to a panel on the mainform, and remove it, then allow the background thread to fire the event. The handler enters but this time 'InvokeRequired' is set to true so it properly invokes itself in the mainthreads context avoiding the exception.</p>
  
  <p>Can someone explain to me why the act of adding it to a panel then removing it fixes the error? </p>
  
  <p>There is no onLoad events for the form so everything should be properly instantiated without it being drawn.</p>
  
  <p>thanks!
  stephanie</p>