title: How do you open a WPF window in its own thread, then close it?
body: <p>I am trying to give some user entertainment, and show a "please wait" window, with Marquee, during the loading of a separate complex Window.  I am attempting to do this by loading the Window in a new thread, like this:</p>
  
  <pre><code>
      Public Function ShowPleaseWait() As System.Threading.Thread
          Dim PleaseWait As New System.Threading.Thread(AddressOf LoadPleaseWait)
          PleaseWait.SetApartmentState(System.Threading.ApartmentState.STA)
          PleaseWait.IsBackground = True
          PleaseWait.Start()
  
          Return PleaseWait
      End Function
  
      Public Sub LoadPleaseWait()
          Dim window As New windowPleaseWait
          Try
              window.Show()
              System.Windows.Threading.Dispatcher.Run()
          Catch e As System.Threading.ThreadAbortException
              window.Close()
              window = Nothing
          End Try
      End Sub 
  </code></pre>
  
  <p>In the calling code, it calls <code>ShowPleaseWait</code> and saves the Thread for later.. To close the window, it calls <code>Thread.Abort</code>, on the saved thread. This in turn will causes it to enter the <code>Catch</code>.  I have tried, many different ways, with and without the catch.</p>
  
  <p>This works incredibly, the first time it is called.  However, additional calls will fail at <code>window.Show()</code> with the exception: <code>The calling thread cannot access this object because a different thread owns it.</code>.</p>
  
  <p>This really puzzles me as the window was created one line above the call to <code>window.Show</code> and is local.  How is it owned by a different thread?  How can I fix this?</p>