title: How to close current window (in Code) when launching new Window
body: <pre><code>SignInWindow signIn= new SignInWindow();
  signIn.ShowDialog();
  </code></pre>
  
  <p>The above code is in my MainWindow class.</p>
  
  <p>When the new Window is shown, I want the current window to close. Whats the best way to do this?</p>
  
  <p>My application is a C# WPF application</p>
  
  <hr>
  
  <p>I've tries this but when it's called, my application exits</p>
  
  <pre><code>    static private void CloseAllWindows()
      {
          for (int intCounter = App.Current.Windows.Count - 1; intCounter &gt;= 0; intCounter--)
              App.Current.Windows[intCounter].Close();
      }
  </code></pre>