title: The Calling thread cannot access this object because a different thread owns it - WPF
body: <p>I have hardware which is connected through socket.</p>
  <p>I have to check whether the hardware is connected or not every 5 seconds, which is indicated by a checkbox.</p>
  <p>I have implemented a function:</p>
  <pre><code>private static System.Timers.Timer aTimer;
  public MainWindow()
  {
      InitializeComponent();
      client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client);
      aTimer = new System.Timers.Timer();
      aTimer.AutoReset = true;
      aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
  
      aTimer.Interval = 2000;
      aTimer.Enabled = true;
  }
  
  private void OnTimedEvent(object source, ElapsedEventArgs e)
  {
      if (client.Connected == true)
      {
          Console.WriteLine(&quot;Not Connected&quot;);
          CheckBox.IsChecked = false;
      }
      else
      {
          Console.WriteLine(&quot;Connected&quot;);
          CheckBox.IsChecked = false;
      }
  }
  </code></pre>
  <p>But when I am running the application it is throwing error:</p>
  <pre><code>The calling thread cannot access this object because a different thread owns it.
  </code></pre>
  <p>I researched and learned about <strong>Dispatcher.Invoke</strong>, but not been able to implement that in my code.</p>