title: How can ThreadPool directly access the controls of another thread?
body: <p>I have heard that thread cannot access controls of other threads directly.</p>
  
  <p>So our professor gave us a snippet</p>
  
  <pre><code>private void UpdateUI()
  {
      if(this.InvokeRequired)
          this.Invoke(new MethodInvoker(UpdateUI));
      else
          this.Refresh();
  }
  </code></pre>
  
  <p>and said that <code>InvokeRequired</code> property returns false it the thread is not the owner of the control and then we should call <code>Invoke()</code> method to tell the owner thread to execute <code>UpdateUI()</code> method. Which then updates the UI.</p>
  
  <p>But recently, just out of curiosity I commented <code>InvokeRequired</code> and <code>Invoke()</code></p>
  
  <pre><code>private void UpdateUI()
  {
      //if(this.InvokeRequired)
          //this.Invoke(new MethodInvoker(UpdateUI));
      //else
          this.Refresh();
  }
  </code></pre>
  
  <p>and was surprised to see that ThreadPool could access controls of another thread and now I feel that I haven't completely understood the concept of ThreadPool.</p>
  
  <p>Here's is the complete code.</p>
  
  <pre><code>using System;
  using System.Threading;
  using System.Drawing;
  using System.Windows.Forms;
  
  class MainForm : Form
  {
      public MainForm()
      {
          this.Text = "Hello WinForms";
          ThreadPool.QueueUserWorkItem(Clock);
      }
  
      private void Clock(object state)
      {
          for(;;)
          {
              Thread.Sleep(1000);
              UpdateUI();
          }
      }
  
      private void UpdateUI()
      {
          //if(this.InvokeRequired)
          //    this.Invoke(new MethodInvoker(UpdateUI));
          //else
              this.Refresh();
      }
  
      protected override void OnPaint(PaintEventArgs pe)
      {
          using(Pen pen = new Pen(Color.Red, 2))
              pe.Graphics.DrawRectangle(pen, 20, 20, 125, 30);
  
          pe.Graphics.DrawString(DateTime.Now.ToString(), this.Font, Brushes.Blue, 25, 30);
      }
  
      [STAThread]
      public static void Main()
      {
          Application.Run(new MainForm());
      }
  }
  </code></pre>
  
  <p>Could someone please explain me how does this happen?</p>
  
  <p>Thanks.</p>