title: C# Asynchronous Task for a Stock Ticker
body: <p>I've been trying to learn more about asynchronous tasks and threading but not making a ton of headway. </p>
  
  <p>I'm trying to load an "Engine" type of thread that will run in the background upon launch and be able to access the UI Thread to update variables, without hanging the UI Thread.</p>
  
  <p>In the below code, Engine is called, and a Ticker object is created which holds the current value of (Litecoin/USD) called Last, also holds several other values that would be useful. This code successfully assigns the current value to label1.text. I don't necessarily need code but what approach would I take to create a ticker object in the background every second and update the UI thread with each new Ticker objects values. </p>
  
  <p>Is this a good case for a background worker?</p>
  
  <pre><code>    private void Form1_Load(object sender, EventArgs e)
      {
          Engine();
      }
      private void Engine()
      {
          Ticker ltcusd = BtceApi.GetTicker(BtcePair.LtcUsd);
          label1.Text = "LTC/USD:" + ltcusd.Last;
      }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  If I do the following, label1 throws an InvalidOperationException due to a Cross-thread operation attempt (label1 in the UI thread).</p>
  
  <pre><code>    private void Form1_Load(object sender, EventArgs e)
      {
          var t = Task.Factory.StartNew(() =&gt; Engine());
          t.Start();
      }
      private void Engine()
      {
          while (true)
          {
              Thread.Sleep(1000);
              Ticker ltcusd = BtceApi.GetTicker(BtcePair.LtcUsd);
              label1.Text = "LTC/USD: " + ltcusd.Last;
          }
      }
  </code></pre>