title: Change WPF mainwindow label from another class and separate thread
body: <p>Im working on a WPF application. I have a label called "Status_label" in <code>MainWindow.xaml</code>. and I want to change its content from a different class (signIn.cs).
  Normally I'm able to do this</p>
  
  <pre><code>var mainWin = Application.Current.Windows.Cast&lt;Window&gt;().FirstOrDefault(window =&gt; window is MainWindow) as MainWindow;
  mainWin.status_lable.Content = "Irantha signed in";
  </code></pre>
  
  <p>But my problem is,when I'm trying to access it via different thread in signIn.cs class, it gives an error:</p>
  
  <pre><code>The calling thread cannot access this object because a different thread owns it.
  </code></pre>
  
  <p>Can I solve this by using <code>Dispatcher.Invoke(new Action(() =&gt;{..........</code> or something else?</p>
  
  <p><strong>EDIT:</strong>
  I'm gonna call this label change action from different class as-well-as separate thread</p>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>&lt;Label HorizontalAlignment="Left" Margin="14,312,0,0" Name="status_lable" Width="361"/&gt;
  </code></pre>
  
  <p><strong>SignIn.cs</strong></p>
  
  <pre><code>    internal void getStudentAttendence()
      {
          Thread captureFingerPrints = new Thread(startCapturing);
          captureFingerPrints.Start();
      }
  
  void mySeparateThreadMethod()
  {
      var mainWin = Application.Current.Windows.Cast&lt;Window&gt;().FirstOrDefault(window =&gt; window is MainWindow) as MainWindow;
      mainWin.status_lable.Dispatcher.Invoke(new Action(()=&gt; mainWin.status_lable.Content ="Irantha signed in"));
  }
  </code></pre>
  
  <p>line var mainWin return error<code>The calling thread cannot access this object because a different thread owns it.</code></p>
  
  <p>Please guide me,</p>
  
  <p>Thank you</p>