c++winapiwindows-11power-saving

SetThreadExecutionState with just ES_CONTINUOUS don't enable sleep on Windows 11


I call SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS) and my PC doesn't sleep while a task is working. It's what I want.

When the task has finished, I call SetThreadExecutionState(ES_CONTINUOUS), and thought that the PC would be able to go to sleep, but it doesn't. It goes to sleep only if I send it to sleep manually.

How to return to the normal sleep timer?

PS: it's on Windows 11.


Solution

  • I've found problem. I fired SetThreadExecutionState from different threads ;)