System Sleep Criteria

[This is preliminary documentation and subject to change.]

As long as the system determines that there is application activity, it will not put the system or any devices into the sleeping state. The system can detect certain activities, such as user input or network communications. However, there are other activities that the system cannot track. For example, a presentation application requires the screen for display. However, it may appear that the application is idle during the presentation, causing the system to turn off the screen. To notify the system that your application is busy, use the SetThreadExecutionState function. This function prevents the system from placing the system or any devices into the sleeping state while the application is running.

Presentation and multimedia applications must call SetThreadExecutionState with ES_DISPLAY_REQUIRED so that the system will know that it should not put the display device into the sleeping state. Event-handling applications, such as utilities for managing incoming faxes, must call SetThreadExecutionState with ES_SYSTEM_REQUIRED, handle the event, then clear the flag so the system can put the system back into the sleeping state. Note that most productivity applications do not need to use SetThreadExecutionState because the system can usually determine activity by user input.

To maintain the time since the last user input, the system uses a display idle timer and a system idle timer. The system compares the idle timers to the time-out values the user sets for the display and system by using the Power Management control panel application. If the display idle timer value is greater than the display time-out value, and no threads have requested the display by calling SetThreadExecutionState with ES_DISPLAY_REQUIRED, the system puts the display into the sleeping state. Similarly, if the system idle timer is greater than the system time-out value, and no applications have requested the system by calling SetThreadExecutionState with ES_SYSTEM_REQUIRED, the system puts the system into the sleeping state.

The system maintains a count of applications that have called SetThreadExecutionState. The system tracks each thread that calls SetThreadExecutionState and adjusts the counter accordingly. If this counter reaches zero and there has not been any user input, the system puts the system into the sleeping state by calling SetSystemPowerState.

When you call the SetSystemPowerState function with fForce set to TRUE, the system generally puts the system into the sleeping state. However, if the next scheduled wake-up time is less than 30 seconds from the current time, SetSystemPowerState leaves the system in the working state and returns FALSE, regardless of the value of fForce.