Home
About
Blog
Media Gallery

Prevent sleep idle timeout


// Prevent sleep idle time-out for system and display (see MS ref for away option as well).
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);

// Do work and keep computer and display awake while doing it...

// Clear EXECUTION_STATE flags to disable awake states and allow the system to idle to sleep normally.
SetThreadExecutionState(ES_CONTINUOUS);


MS ref

Original Post: Sep 22nd, '22 16:06 CEST.
Updated: Sep 26th, '22 11:22 CEST.

Tags: C/C++