Should Application.Current.Shutdown()
NOT be used as a best practice to close a WPF application?
I have a small, multiple window application and the "shutdown" seems to work nicely for all my exit commands. However, I have been told to always use Application.Current.MainWindow.Close()
.
MainWindow.Close
won't even do anything if the ShutdownMode
is not set respectively. You can do what you want, it should just fit what one expects.
(Shutdown
will ignore the fact that some Closing
event was cancelled, so that would be one thing you need to take into consideration)
Also:
Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations:
When ShutdownMode is set to OnLastWindowClose.
When the ShutdownMode is set to OnMainWindowClose.
When a user ends a session and the SessionEnding event is either unhandled, or handled without cancellation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With