系统事件和从睡眠状态恢复
想象一下,我正在创建一个应用程序来测量某个用户登录计算机的时间(我正在编写的实际应用程序有所不同,但这并不重要)。
我需要跟踪用户何时登录、注销、何时挂起计算机(“关机”菜单中的“待机”选项)以及计算机何时从睡眠状态恢复。
我正在使用 SystemEvents
(具体来说,PowerModeChanged
和 SessionSwitch
事件),它大部分都有效,但有一个例外:
当计算机挂起时,会正确引发 PowerModeChanged
事件与模式暂停
。
当计算机恢复时,将引发 PowerModeChanged
,模式为 Resume
。到目前为止,一切都很好。
之后,将引发 SessionSwitch
事件,原因是 SessionLock
。但是当我最终在恢复后登录时,没有SessionUnlock
。
此行为发生在 Windows XP 上,我需要它才能在 XP、Vista 和 7 上正常工作。
有没有办法接收此解锁?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我的一位处理程序存在未捕获的异常。显然,这阻止了后续事件的发生。
Turns out there was an uncaught exception in one of my handlers. Apparently, this stopped subsequent events from firing.