Which is the preferred method of closing a C# WPF Application?
1) calling Window.Close() within the Main Window
2) Calling Application.Current.Shutdown( 0 ) within the Main Window.
Are the two semantically equivalent or is there a subtle distinction that I need to be aware of?
The first only closes the window, depending on your Application.ShutdownMode
that may not even shutdown the application.
How you exit the application depends solely on what you want to do, i for one tend to define the Application.MainWindow
and set the ShutdownMode
to OnMainWindowClose
so all the small dialogues do not prevent the application from closing (since the default is OnLastWindowClose
).