Catch windows shutdown event in a wpf application

2019-02-09 07:00发布

I have a c# WPF application that needs to save data when it closes. 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). but i cant figure out how to achieve this in a WPF application.

I'm trying to halt the shutdown until my program is ready to exit

标签: c# wpf wndproc
1条回答
甜甜的少女心
2楼-- · 2019-02-09 07:19

There is a built-in event Application.SessionEnding - this event fires when the user logs off or shuts down the computer... you just need to subscribe to that and put your code to save date etc. in there...

查看更多
登录 后发表回答