Application.Current.MainWindow.Close vs Application.Current.Shutdown

Should Application.Current.Shutdown() NOT be used as best practice to close a WPF application?

I have a small application with multiple windows, and "shutdown" seems to work fine for all of my exit commands. However, I was told to always use Application.Current.MainWindow.Close() .

+7
source share
1 answer

MainWindow.Close do nothing if ShutdownMode not set accordingly. You can do what you want, it should just be as expected.

( Shutdown will ignore the fact that some Closing event has been canceled, so this will be one thing that you should take into account)

Also :

Shutdown is implicitly called by Windows Presentation Foundation (WPF) in the following situations:

  • When ShutdownMode is set to OnLastWindowClose.

  • If ShutdownMode is set to OnMainWindowClose.

  • When the user ends the session and the SessionEnding event is either not processed or processed without cancellation.

+6
source

All Articles