0

该应用程序在计算机上运行的时间更长,但如果计算机进入睡眠模式,就会出现问题。有什么办法可以防止进入睡眠模式?

4

1 回答 1

2

class像这样定义:

internal static class NativeMethods
 {

     // Import SetThreadExecutionState Win32 API and necessary flags

     [DllImport("kernel32.dll")]

     public static extern uint SetThreadExecutionState(uint esFlags);

     public const uint ES_CONTINUOUS = 0x80000000;

     public const uint ES_SYSTEM_REQUIRED = 0x00000001;

 }

把它放到main方法中:(确保它在application.run调用之前)

// Set new state to prevent system sleep. (Note: still allows screen saver)

var previousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
于 2013-07-29T10:11:59.503 回答