title: WPF: The calling thread cannot access this object because a different thread owns it
body: <p>I know there are similar questions like <a href="https://stackoverflow.com/questions/9732709/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it?noredirect=1&amp;lq=1">Here</a> And <a href="https://stackoverflow.com/questions/2728896/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it?noredirect=1&amp;lq=1">Here</a>, I looked them all, but they seems not work for me.</p>
  
  <p>I have a thread:</p>
  
  <pre><code>private void Sample()
  {
        Thread t = new Thread(new ThreadStart(Sample_Thread));
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
  }
  </code></pre>
  
  <p>In the Sample_Thread, I previously called <code>MessageBox</code> which works fine.</p>
  
  <pre><code>private void Sample_Thread()
  {
       try{ ... }
       catch(Exception e)
       {
            MessageBox.Show("SampleText");
       }
  }
  </code></pre>
  
  <p>Now I try to call <code>ModernDialog</code> instead of <code>MessageBox</code>, it gives me error <code>'The calling thread cannot access this object because a different thread owns it.'</code>
   so I change my code to this:</p>
  
  <pre><code>private void Sample_Thread()
  {
       try{ ... }
       catch(Exception e)
       {
              Dispatcher.CurrentDispatcher.Invoke(() =&gt;
              {
                  ModernDialog.ShowMessage("SampleText");
              });
       }
  }
  </code></pre>
  
  <p>But this still got that same error, how should I fix this? Thanks!</p>