欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

WPF 技巧和窍门 - 防止系统休眠

最编程 2024-04-15 11:34:25
...
public static class SystemSleepTool { //定义API函数 [DllImport("kernel32.dll")] static extern uint SetThreadExecutionState(ExecutionFlag flags); [Flags] enum ExecutionFlag : uint { ES_SYSTEM_REQUIRED = 0x00000001, ES_DISPLAY_REQUIRED = 0x00000002, ES_CONTINUOUS = 0x80000000, } /// <summary> ///阻止系统休眠 /// </summary> public static void PreventSleep() { SetThreadExecutionState(ExecutionFlag.ES_SYSTEM_REQUIRED | ExecutionFlag.ES_DISPLAY_REQUIRED | ExecutionFlag.ES_CONTINUOUS); } /// <summary> ///恢复系统休眠 /// </summary> public static void RestoreSleep() { SetThreadExecutionState(ExecutionFlag.ES_CONTINUOUS); } }