1

I'm working on a program that requires the PC to stay online at all times. I want to allow my program to run while the monitor turns off but prevent sleep mode.

For example if I have auto sleep set to enable after 2 minutes of inactivity I'd like this process to begin and the monitor to turn off but the CPU stay active and allow my program to utilize the CPU.

I thought this line would do it but sleep mode still occurs.

 SetThreadExecutionState(ES_SYSTEM_REQUIRED);

What am I doing wrong?

mocode9
  • 229
  • 3
  • 16
  • 4
    Have you looked at https://stackoverflow.com/questions/629240/prevent-windows-from-going-into-sleep-when-my-program-is-running?rq=1 ? – Cyrille Ka Jan 05 '17 at 21:29
  • 2
    You need to give us an operating system tag. This is different on Windows, Mac, Linux, BSD, Android, etc. – Zan Lynx Jan 05 '17 at 21:32
  • NOT a duplicate of http://stackoverflow.com/questions/629240/prevent-windows-from-going-into-sleep-when-my-program-is-running as that specifies different requirements. – Harry Johnston Jan 05 '17 at 22:53

1 Answers1

2

You need to keep calling that function (there's a timer which disables its setting). or call it with ES_SYSTEM_REQUIRED | ES_CONTINUOUS as the parameter.