title: How do I get information from a closed window in App.xaml.cs?
body: <p>I have multiple windows. My LoginWindow has to validate the user. If this window is canceled the complete application should shutdown. If the user enter the correct login, the LoginWindow should be closed and the MainWindow open.</p>
  
  <p><a href="https://i.stack.imgur.com/Qrk54.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qrk54.jpg" alt="Flowchart"></a></p>
  
  <p><strong>Question:</strong>
  My problem is at the yellow diamond: How to determine the state of the login process?</p>
  
  <p>That is my current state. </p>
  
  <pre><code>public partial class App : Application
  {
      [STAThread]
      public static void Main()
      {
          var app = new App();
          var login = new LoginWindow();
          if (app.Run(login) == 1) //&lt;-- Problem: How to get the state from login?
          {
              var mainapp = new MainWindow();
              app.Run(mainapp);
          }
      }
  }
  </code></pre>
  
  <p>I tried to get an exitcode from the loginwindow by using  <code>Application.Current.Shutdown(1);</code> but it cause an InvalidOperationException on <code>app.Run(mainapp);</code>, because <code>Shutdown</code> closes the complete application.</p>