How to detect when Windows 8 goes to sleep or resumes

狂风中的少年 提交于 2019-12-04 17:21:00

For desktop apps, you can use SystemEvents.PowerModeChanged event to know if Windows is going into sleep state. I don't know if this works for the tablets too, but you can try it...

From MSDN:

• Resume The operating system is about to resume from a suspended state.

• StatusChange A power mode status notification event has been raised by the operating system. This might indicate a weak or charging battery, a transition between AC power and battery, or another change in the status of the system power supply.

• Suspend The operating system is about to be suspended.

SystemEvents.PowerModeChanged += OnPowerChange;

private void OnPowerChange(object s, PowerModeChangedEventArgs e) 
{
    switch ( e.Mode ) 
    {
        case PowerModes.Resume: 
        break;
        case PowerModes.Suspend:
        break;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!