title: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
body: <p>I have a scenario. (Windows Forms, C#, .NET)</p>
  <ol>
  <li>There is a main form which hosts some user control.</li>
  <li>The user control does some heavy data operation, such that if I directly call the <code>UserControl_Load</code> method the UI become nonresponsive for the duration for load method execution.</li>
  <li>To overcome this I load data on different thread (trying to change existing code as little as I can)</li>
  <li>I used a background worker thread which will be loading the data and when done will notify the application that it has done its work.</li>
  <li>Now came a real problem. All the UI (main form and its child usercontrols) was created on the primary main thread. In the LOAD method of the usercontrol I'm fetching data based on the values of some control (like textbox) on userControl.</li>
  </ol>
  <p>The pseudocode would look like this:</p>
  <p><strong>CODE 1</strong></p>
  <pre><code>UserContrl1_LoadDataMethod()
  {
      if (textbox1.text == &quot;MyName&quot;) // This gives exception
      {
          //Load data corresponding to &quot;MyName&quot;.
          //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage.
      }
  }
  </code></pre>
  <p>The Exception it gave was</p>
  <blockquote>
  <p>Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.</p>
  </blockquote>
  <p>To know more about this I did some googling and a suggestion came up like using the following code</p>
  <p><strong>CODE 2</strong></p>
  <pre><code>UserContrl1_LoadDataMethod()
  {
      if (InvokeRequired) // Line #1
      {
          this.Invoke(new MethodInvoker(UserContrl1_LoadDataMethod));
          return;
      }
  
      if (textbox1.text == &quot;MyName&quot;) // Now it won't give an exception
      {
      //Load data correspondin to &quot;MyName&quot;
          //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage
      }
  }
  </code></pre>
  <p>But it still seems that I've come back to square one. The Application again
  becomes unresponsive. It seems to be due to the execution of line #1 if condition. The loading task is again done by the parent thread and not the third that I spawned.</p>
  <p>I don't know whether I perceived this right or wrong. I'm new to threading.</p>
  <p>How do I resolve this and also what is the effect of execution of Line#1 if block?</p>
  <p><strong>The situation is this</strong>: I want to load data into a global variable based on the value of a control. I don't want to change the value of a control from the child thread. I'm not going to do it ever from a child thread.</p>
  <p>So only accessing the value so that the corresponding data can be fetched from the database.</p>