0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Anton111111
  • 656
  • 1
  • 7
  • 23
  • https://stackoverflow.com/questions/71664584/windows-how-to-initiate-modern-standby-from-session-0 – Hans Passant Apr 26 '23 at 13:48
  • Reproduced. It seems the sleep time adheres to the time of power plans and `SetThreadExecutionState` cannot interfere the internal timer. Also see https://learn.microsoft.com/en-us/answers/questions/999348/setthreadexecutionstate-without-es-continuous-does, https://stackoverflow.com/questions/72436579/setthreadexecutionstatees-system-required-does-not-prevent-system-sleep-on-win – YangXiaoPo-MSFT Apr 27 '23 at 03:05

1 Answers1

0

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

Anton111111
  • 656
  • 1
  • 7
  • 23