Search code examples
c#session-state

Cancel Lock Session Event


Is it possible to cancel the Session Lock Event?

I have this code to detect if the session lock is thrown and it works. I just want to be able to cancel the session lock from happening.

My Code: ...

SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);

...

void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
    {
        switch(e.Reason)
        {
            case SessionSwitchReason.SessionLock:
                startAlarm = true;
                alarm.Play();
                this.WindowState = WindowState.Maximized;
                this.Show();
                InfoText.Text = "PLEASE REMOVE YOUR ID CARD";
                break;

            case SessionSwitchReason.SessionUnlock:
                startAlarm = false;
                alarm.Stop();
                break;

            default:
                break;
        }
    }

Solution

  • As @Arnaud F says in the comment. It is impossible.