title: Accessing UI controls in Task.Run with async/await on WinForms
body: <p>I have the following code in a WinForms application with one button and one label:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private async void button1_Click(object sender, EventArgs e)
          {
              await Run();
          }
  
          private async Task Run()
          {
              await Task.Run(async () =&gt; {
                  await File.AppendText("temp.dat").WriteAsync("a");
                  label1.Text = "test";
              });    
          }
      }
  }
  </code></pre>
  
  <p>This is a simplified version of the real application I'm working on. I was under the impression that by using async/await in my <code>Task.Run</code> I could set the <code>label1.Text</code> property. However, when running this code I get the error that I'm not on the UI thread and I can't access the control.</p>
  
  <p>Why can't I access the label control?</p>