SystemEvents.SessionEnding not firing
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am developing an windows forms application in c# .net 4.0. I want to capture windows logoff event. Here is the code: public Form1() { InitializeComponent(); SystemEvents.SessionEnding += (s, e) => { if (e.Reason == SessionEndReasons.Logoff) { MessageBox.Show("LogOff"); } else if (e.Reason == SessionEndReasons.SystemShutdown) { MessageBox.Show("ShutDown"); } }; } Why isnt my sessionEnding firing? 回答1: It depends on the configuration that is set on gpedit.msc. Open gpedit.msc, navigate to Computer Configuration > Administrative Templates >