Why isn't my WPF closing event being fired for system closes?

前端 未结 2 675
慢半拍i
慢半拍i 2021-01-15 03:53

I have the following line in my Window stanza in the XAML file:

    Closing=\"Window_Closing\"

I originally thought that the w

相关标签:
2条回答
  • 2021-01-15 04:26

    According to the documentation page for the Closing event:

    If a session ends because a user logs off or shuts down, Closing is not raised; handle SessionEnding to implement code that cancels application closure.

    Therefore you'll want to make sure you handle the SessionEnding event as well as the Closing event. The SessionEnding event could be used to automatically save the current state to a temporary file that will be loaded again the next time the application starts. But if you do want to prompt the user, you can do so with a modal dialog box in SessionEnding but they will likely see the Windows screen that warns about unresponsive applications, giving them the chance to kill the process without responding to your dialog.

    0 讨论(0)
  • 2021-01-15 04:33

    Try the Closed event instead: Closed="Window_Closing"

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