title: How do I open a window on a new thread?
body: <p>I have a options window and a window that displays color based on these options and Kinect data. So far everything's on one thread (as far as I know; I haven't done any threading).</p>
  
  <p>Now, I'm adding an option to open a viewer window that will need to be updated with lowest possible latency. All this entails is creating a window and showing it:</p>
  
  <pre><code>viewer = new SkeletalViewer.MainWindow();
  viewer.Show();
  </code></pre>
  
  <p>When this event fires, the color window stops displaying colors (i.e. the event that fires 30 times a second on the main thread stops firing), but the viewer is displayed perfectly. I want  the viewer and the color window to both be updated.</p>
  
  <p>From reading other questions, it sounds like the solution is to create the viewer on a new thread. I'm encountering a lot of problems with this, though.</p>
  
  <p>This fires when I click the button to open the viewer:</p>
  
  <pre><code>private void launchViewerThread_Click(object sender, RoutedEventArgs e)
      {
          Thread viewerThread = new Thread(delegate()
          {
              viewer = new SkeletalViewer.MainWindow();
              viewer.Dispatcher.Invoke(new Action(delegate() 
                  {
                      viewer.Show();
                  }));
          });
  
          viewerThread.SetApartmentState(ApartmentState.STA); // needs to be STA or throws exception
          viewerThread.Start();
  
      }
  </code></pre>
  
  <p>Regardless of if I just call viewer.Show() or Invoke() it as above, the line throws an exception: <strong>Cannot use a DependencyObject that belongs to a different thread than its parent Freezable.</strong> Here's how I understand Invoke(): it accesses viewer's dispatcher, which knows what thread the object is running on, and can then call methods from that thread.</p>
  
  <p>Should I be trying to put this viewer on a new thread? Is the problem even a question of threads? The user will not be interacting with the viewer.</p>
  
  <p>Anyone know why this doesn't work? Thanks for the help.</p>