在 C# 中检测系统从睡眠中唤醒的事件 [英] Event to detect System wake up from sleep in C#
问题描述
我需要检测系统电源状态模式.准确地说,我需要一个在 Windows 7 从睡眠中醒来时触发的事件.我已经在使用了:
I need to detect the system power state mode. To be precise, I need an event which fires up when windows 7 wakes up from sleep. I am already using:
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
但是这个事件的问题是它被引发了四次:可能是在计算机进入睡眠模式和计算机唤醒之后.我想要一个仅在计算机唤醒时引发的事件.有什么活动吗?
But the problem with this event is that it is raised up four times: possibly when computer goes into sleep mode and after computer wakes up. I want an event which is raised at computer wake up only. Is there any event for this?
推荐答案
SystemEvents.PowerModeChanged += OnPowerChange;
private void OnPowerChange(object s, PowerModeChangedEventArgs e)
{
switch ( e.Mode )
{
case PowerModes.Resume:
break;
case PowerModes.Suspend:
break;
}
}
您可能应该阅读以下内容:http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx
You should probably read this: http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx
这篇关于在 C# 中检测系统从睡眠中唤醒的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!