title: How to invoke a UI method from another thread
body: <p>Playing round with Timers. 
  Context: a winforms with two labels. </p>
  
  <p>I would like to see how <code>System.Timers.Timer</code> works so I've not used the Forms timer. 
  I understand that the form and myTimer will now be running in different threads.
  Is there an easy way to represent the elapsed time on <code>lblValue</code> in the following form?</p>
  
  <p>I've looked here on <a href="http://msdn.microsoft.com/en-us/library/ms171728%28v=vs.80%29.aspx" rel="noreferrer">MSDN</a> but is there an easier way !</p>
  
  <p>Here's the winforms code:</p>
  
  <pre><code>using System.Timers;
  
  namespace Ariport_Parking
  {
    public partial class AirportParking : Form
    {
      //instance variables of the form
      System.Timers.Timer myTimer;
      int ElapsedCounter = 0;
  
      int MaxTime = 5000;
      int elapsedTime = 0;
      static int tickLength = 100;
  
      public AirportParking()
      {
          InitializeComponent();
          keepingTime();
          lblValue.Text = "hello";
      }
  
      //method for keeping time
      public void keepingTime() {
  
          myTimer = new System.Timers.Timer(tickLength); 
          myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
  
          myTimer.AutoReset = true;
          myTimer.Enabled = true;
  
          myTimer.Start();
      }
  
  
      void myTimer_Elapsed(Object myObject,EventArgs myEventArgs){
  
          myTimer.Stop();
          ElapsedCounter += 1;
          elapsedTime += tickLength; 
  
          if (elapsedTime &lt; MaxTime)
          {
              this.lblElapsedTime.Text = elapsedTime.ToString();
  
              if (ElapsedCounter % 2 == 0)
                  this.lblValue.Text = "hello world";
              else
                  this.lblValue.Text = "hello";
  
              myTimer.Start(); 
  
          }
          else
          { myTimer.Start(); }
  
      }
    }
  }
  </code></pre>