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

前端 未结 1 1534
故里飘歌
故里飘歌 2021-01-05 09:36

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 \"s

相关标签:
1条回答
  • 2021-01-05 09:57

    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.

    0 讨论(0)
提交回复
热议问题