title: How to update UI (text fields) during long running function?
body: <p>I know that the question may not make sense, and I'm having a tough time trying to think of a way to explain it, so I will show a snippet of code to help. I'm using Winforms on visual studio express 2010:</p>
  
  <pre><code>private void button1(object sender, EventArgs e)
      {
          txtOutput.Text += "Auto-collecting variables. This may take several minutes";
          string v = foo();
          txtOutput.Text += "\n" + v;
          string b = bar();
          txtOutput.Text += "\n" + b;
  
          txtOutput.SelectionStart = txtOutput.Text.Length;
          txtOutput.ScrollToCaret(); //scrolls to the bottom of textbox
      }
  </code></pre>
  
  <p>So basically, when the user clicks button1, I want "Auto-collecting variables..." to be displayed in the textbox, and then have foo() execute, display that, and then have bar() execute, and then display that.</p>
  
  <p>What is currently happening is that foo() and bar() execute, and then everything is displayed all at once after foo() and bar() have executed (functions that take several minutes). Is there anyway to fix this, or is there a work around?</p>
  
  <p>Edit: Version of C# is 4.0. If I update to 4.5 or 5.0, will computers without .NET 4.5/5.0 be able to run the .exe?</p>