110,533
社区成员
发帖
与我相关
我的任务
分享
[DllImport("kernel32.dll")]
public static extern uint SetThreadExecutionState(uint esFlags);
//禁止休眠和睡眠
public static void DisableStandby()
{
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
}
//允许睡醒和休眠
public static void EnableStandby()
{
SetThreadExecutionState(ES_CONTINUOUS);
}
const uint ES_SYSTEM_REQUIRED = 0x00000001;
const uint ES_DISPLAY_REQUIRED = 0x00000002;
const uint ES_CONTINUOUS = 0x80000000;