Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wpf

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().

like image 675
Paul Matovich Avatar asked Feb 29 '12 19:02

Paul Matovich


1 Answers

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.

like image 104
H.B. Avatar answered Nov 02 '22 21:11

H.B.