title: Setting the main window as a dialog owner (message box) called from a STA thread
body: <p>This is a function that calls a custom C# message box. The function is called from a simulation process that runs inside a thread that is not the UI thread.</p>
  
  <pre><code>public Output.ButtonResult msgboxYesNo(string Text, string title) {
      Output.Message_Box msg = new Output.Message_Box();
  
      msg.Dispatcher.Invoke(new Action(() =&gt; {
          msg.seeQuestion(Text, title);
          msg.Topmost = true;
          Application.Current.MainWindow.Dispatcher.Invoke(new Action(()
                            =&gt; { msg.Owner = Application.Current.MainWindow; }));
          msg.ShowDialog();                
      }));
  
      return msg.result;
  }
  </code></pre>
  
  <p>The problematic line is this one:</p>
  
  <pre><code>Application.Current.MainWindow.Dispatcher.Invoke(new Action(() =&gt;
                                { msg.Owner = Application.Current.MainWindow; }));
  </code></pre>
  
  <p>And it throws this:</p>
  
  <blockquote>
    <p>The calling thread cannot access this object because a different
    thread owns it</p>
  </blockquote>
  
  <p>Because I want to set the main window as the owner of the custom message box, which is called within a separated thread.</p>
  
  <p>How can I set the main form as the owner of the message box?</p>
  
  <p>(I hope I explained the issue clear enough, the forms are WPF)</p>