title: Win Forms Label Updates Super Slow
body: <p>I have a Windows Forms application written in C# that does some automated testing. My test runs on the thread pool. The UI has a bunch of labels to display the data read from an external device. During the test, a method writes the new values to a singleton class. The singleton class broadcasts the value change and an event handler in the forms code does the updating after invoking on the UI thread. My problem is that it takes about 1.5 seconds just to update the UI (72 Labels). Why does it take so long? FYI, there is only one event broadcast for all 72 values, not one broadcast for each of the 72 values.</p>
  
  <p>Here is the code (ProgramData.MaximumUnits = 18):</p>
  
  <pre><code>this.InvokeIfRequired(() =&gt;
  {
      var stopwatch = new Stopwatch();
      var rawData = TestData.Instance.RawDataDisplay;
      stopwatch.Start();
      for (int i = 0; i &lt; ProgramData.MaximumUnits; i++)
      {
          Frequency1Label[i].Text = rawData[i].F1;
          Frequency2Label[i].Text = rawData[i].F2;
          TempSensorLabel[i].Text = rawData[i].T1;
          UnitInfoLabel[i].Text = rawData[i].ErrorCode;
      }
      stopwatch.Stop();
      MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString());
  });
  </code></pre>
  
  <p>The elapsed time is usually around 1500ms. I feel like this operation should be performed in less than 100ms.</p>
  
  <p>Why this is a problem: I am displaying externally acquired data that comes in every 1 second. Since it takes 1.5 seconds to update the UI, I am in a serious bind, especially when the data can come in as fast as every half a second.</p>