title: "The calling thread must be STA, because many UI components require this" error when creating a WPF pop-up Window in thread
body: <p>I have a WPF application in which a thread checks some value. In certain cases, I show a pop-up <code>Window</code> in order to display a message. When I create this pop-up window in the thread, an exception is thrown by the pop-up window's constructor:</p>
  
  <blockquote>
    <p><em>"The calling thread must be STA, because many UI components require this."</em></p>
  </blockquote>
  
  <p>How do I resolve this error?</p>
  
  <p>This is my code for creating the pop-up window:</p>
  
  <pre><code>// using System.Threading;
  // using System.Windows.Threading;
  Thread Messagethread = new Thread(new ThreadStart(delegate()
  {
      DispatcherOperation DispacherOP = 
          frmMassenger.Dispatcher.BeginInvoke(
              DispatcherPriority.Normal,
              new Action(delegate()
              {
                  frmMassenger.Show();
              }));
  }));
  Messagethread.Start();
  </code></pre>