Shutting down a WPF application from App.xaml.cs
First remove the StartupUri property from App.xaml and then use the following: protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); bool doShutDown = …; if (doShutDown) { Shutdown(1); return; } else { this.StartupUri = new Uri(“Window1.xaml”, UriKind.Relative); } }