SystemEvents.SessionEnding not firing

前端 未结 2 1216
天涯浪人
天涯浪人 2021-01-17 03:20

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()
    {
              


        
2条回答
  •  别那么骄傲
    2021-01-17 04:01

    1. It depends on the configuration that is set on gpedit.msc.

    Open gpedit.msc, navigate to Computer Configuration > Administrative Templates > System > Shutdown Options and choose Turn off automatic termination of applications that block or cancel shutdown. Since mine laptop configure make it automatic shutdown, so it will never fire session ending

    1. Perhaps you can move your code above into entry point of its windows (in the main).

    2. Perhaps you can override windows message. You can see it in MSDN library documentation. http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending.aspx

    3. Shutdown message pump has been re route by other software and not re route to your apps

提交回复
热议问题