简体   繁体   English

在wpf应用程序中捕获windows shutdown事件

[英]Catch windows shutdown event in a wpf application

I have ac# WPF application that needs to save data when it closes. 我有一个ac#WPF应用程序,它需要在关闭时保存数据。 The Window Closing/Closed events work fine if the user closes the program, but they do not get called if the user logs off/shutdown the computer. 如果用户关闭程序,则窗口关闭/关闭事件可正常工作,但如果用户注销/关闭计算机,则不会调用它们。

I have found ways to catch this event in winforms programs ( here , and here ). 我已经找到了在winforms程序中捕获此事件的方法( 此处此处 )。 but i cant figure out how to achieve this in a WPF application. 但我无法弄清楚如何在WPF应用程序中实现这一点。

I'm trying to halt the shutdown until my program is ready to exit 我正试图停止关机,直到我的程序准备好退出

有一个内置事件Application.SessionEnding - 当用户注销或关闭计算机时会触发此事件...您只需要订阅它并将您的代码保存在那里...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM