SystemEvents.SessionEnding not firing

前端 未结 2 1198
天涯浪人
天涯浪人 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 03:55

    This could be useful to someone.

    if form close event is included

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
        }
    

    then SessionEnding will not be fired, i just encoutered this problem and rectified it

    void SystemEvents_SessionEnding(object sender, Microsoft.Win32.SessionEndingEventArgs e)
        {}
    

    here i need to prevent Form close upon Alt+F4 command, so i added this form closing event this resulted in this issue. so we can integrate session ending event in form close event. Option 2 in Refered from stackoverflow answer

提交回复
热议问题