文章目录

C# 阻止系统休眠

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//定义API函数
[DllImport("kernel32.dll")]
static extern uint SetThreadExecutionState(uint Flags);
const uint ES_SYSTEM_REQUIRED = 0x00000001;
const uint ES_DISPLAY_REQUIRED = 0x00000002;
const uint ES_CONTINUOUS = 0x80000000;

private static void SleepControl(bool isSleep)
{
if (isSleep)
{
//阻止休眠时调用
SetThreadExecutionState(ES_CONTINUOUS ES_DISPLAY_REQUIRED ES_SYSTEM_REQUIRED);
}
else
{
//恢复休眠时调用
SetThreadExecutionState(ES_CONTINUOUS);
}
}

转自:https://blog.csdn.net/BYH371256/article/details/93632055

文章目录