How to exit a WPF app programmatically?-Collection of common programming errors
As wuminqi said, Application.Current.Shutdown();
is irreversible and I believe it is typically used to force an application to close at times such as when a user is logging off or shutting down Windows. Instead, call this.close()
in your main window. This is the same as pressing “ALT-F4” or the close [x] button on the window. This will cause all other owned windows to close and will end up calling Application.Current.Shutdown();
so long as the close action wasn’t cancelled. Please see the MSDN documentation on Closing a Window.
Also, because this.close()
is cancellable you can put in a save changes confirmation dialog in the closing event handler. Simply make an event handler for and change e.Cancel
accordingly. (See the MSDN doc for more details on how to do this)