title: Shutting down a WPF application from App.xaml.cs
body: <p>I am currently writing a WPF application which does command-line argument handling in App.xaml.cs (which is necessary because the Startup event seems to be the recommended way of getting at those arguments). Based on the arguments I want to exit the program at that point already which, as far as I know, should be done in WPF with <code>Application.Current.Shutdown()</code> or in this case (as I am in the current application object) probably also just <code>this.Shutdown()</code>.</p>
  
  <p>The only problem is that this doesn't seem to work right. I've stepped through with the debugger and code after the <code>Shutdown()</code> line still gets executed which leads to errors afterwards in the method, since I expected the application not to live that long. Also the main window (declared in the StartupUri attribute in XAML) still gets loaded.</p>
  
  <p>I've checked the documentation of that method and found nothing in the remarks that tell me that I shouldn't use it during <code>Application.Startup</code> or <code>Application</code> at all.</p>
  
  <p>So, what is the right way to exit the program at that point, i. e. the <code>Startup</code> event handler in an <code>Application</code> object?</p>