Imagine I was creating an application that measured how long a certain user is logged in to a computer (the actual application I'm writing is different, but that doesn't matter).
I need to track when the user logs in, logs out, when he suspends the computer (“stand by“ choice in the Shut Down menu) and when the computer resumes from sleep.
I am using SystemEvents
(specifically, PowerModeChanged
and SessionSwitch
events) for that and it mostly works, with one exception:
When the computer is suspended, the PowerModeChanged
event is correctly raised with the mode Suspend
.
When the computer resumes, PowerModeChanged
is raised with the mode Resume
. So far so good.
Right after that, SessionSwitch
event is raised with the reason SessionLock
. But when I eventually log in after the resume, there is no SessionUnlock
.
This behavior happens on Windows XP, and I need this to work correctly on XP, Vista and 7.
Is there a way how to receive this unlock?
Turns out there was an uncaught exception in one of my handlers. Apparently, this stopped subsequent events from firing.