title: How to access/modify controls on another thread using a System.Timers.Timer?
body: <p>So I'm new to timers and threads and I can't find out how to make a timer that calls a function that edits/modify a control on my MainWindow.</p>
  
  <p>Xaml Code:</p>
  
  <pre><code>&lt;Window x:Class="TimerTest.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
  &lt;TextBox Height="287" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="479" /&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>C# Code:</p>
  
  <pre><code>namespace TimerTest
  {
      public partial class MainWindow : Window
      {
          //Declaring my aTimer as global
          public static System.Timers.Timer aTimer;
          //Function that is called
          public void OnTimedEvent(object source, ElapsedEventArgs e)
          {
              textBox1.Text += "SomeText ";
          }
          public MainWindow()
          {
              InitializeComponent();
              aTimer = new Timer();
              aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
              aTimer.Interval = 1000; // every 5 seconds
              aTimer.Enabled = true;
          }
      }
  }
  </code></pre>
  
  <p>The Error i get:
   "The calling thread cannot access this object because a different thread owns it."
  P.S.: Also I'm not so good with delegates so if you think one might help me in this case, then please post a code sample.</p>