title: The calling thread cannot access this object because a different thread owns it when using animation in wpf window
body: <p>As per our requirement we have to open a WPF window in a new UI thread.</p>
  
  <p>We are opening the window in a new UI thread from the main UI Thread using following code:</p>
  
  <pre><code>Thread winthread = new Thread(new ThreadStart(() =&gt;
  {
      SynchronizationContext.SetSynchronizationContext(
          new DispatcherSynchronizationContext(
              Dispatcher.CurrentDispatcher));
      Window windowObj = new Window();
      Grid gridObj = new Grid();
      MyUserControl ctrl = new MyUserControl();
      gridObj.Children.Add(ctrl);
      windowObj.Content = gridObj;
  
      windowObj.Show();
      System.Windows.Threading.Dispatcher.Run();
  }));
  
  winthread.IsBackground = true;
  winthread.SetApartmentState(ApartmentState.STA);
  winthread.Start();
  </code></pre>
  
  <p>The window will show with <code>MyUserControl</code> as content when the above code executes.
  I am doing some animation like flipping my usercontrol on the mouse double click event. </p>
  
  <p>When I double clicked on it the application starts throwing following exception:</p>
  
  <blockquote>
    <p>The calling thread cannot access this object because a different thread owns it.</p>
  </blockquote>
  
  <p>on line <code>System.Windows.Threading.Dispatcher.Run()</code>.</p>
  
  <p>Can anyone suggest the solution for this problem?</p>