SetThreadExecutionState preventing manual sleep
On Windows 7, I'm seeing that a call to SetThreadExecutionState
with the parameter ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED
ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED
ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED
is preventing the user from manually putting the system to sleep.
Upon opening the Start menu and selecting 'Sleep,' the display turns off, but my application continues processing. This is evident by the fact that the fan continues at full speed and upon waking the computer, I can see that the operations that were being carried out when the sleep occurred have progressed.
How can I allow the user to manually put their computer to sleep while SetThreadExecutionState
is in effect?
Inclusion of the ES_AWAYMODE_REQUIRED option causes this problem. Quoting from the MSDN article:
The ES_AWAYMODE_REQUIRED value should be used only when absolutely necessary by media applications that require the system to perform background tasks such as recording television content or streaming media to other devices while the system appears to be sleeping. Applications that do not require critical background processing or that run on portable computers should not enable away mode because it prevents the system from conserving power by entering true sleep.
链接地址: http://www.djcxy.com/p/62476.html