How to Handle System Sleep/Wake Power Transitions

Challenge

Implement the principles of Application Power Management for Mobility to handle system sleep/wake power transitions. A good user experience and longer battery life are critical factors for mobile systems. Application software has a key role to play in improving user experience as well as in extending battery life.

Solution

Design applications to survive power transitions without requiring a restart or loss of data, and to handle the power transitions transparently with no user interaction. In Windows* operating systems, the sleep power transition refers to switching off the system to a Stand By or a Hibernate mode, and the wake power transition refers to switching on the system from a Stand By or a Hibernate mode. The Stand By and Hibernate modes allow users to switch off and switch on systems much faster than the regular shut down and boot processes.
 
There is no generalized list of tasks for handling system sleep/wake power transitions. The tasks depend on the application and will vary between applications.

Some tasks for applications to consider include the following:

  • Saving state/data prior to the sleep transition and restoring state/data after the wake transition.
  • Closing all open system resource handles such as files and I/O devices prior to the sleep transition.
  • Disconnecting all communication links prior to the sleep transition and reestablishing all communication links after the wake transition.
  • Synchronizing all remote activity (like writing back to remote files or to remote databases) after the wake transition.
  • Stopping any ongoing user activity (for example: streaming video, or file download) prior to the sleep transition and resuming the user activity after the wake transition.

 

Windows operating systems send messages to applications notifying them of system sleep and wake power transitions. Applications should respond to these messages and perform necessary operations to handle the power transitions. The relevant measures for an application to handle system sleep/wake power transitions include the following:

  • Investigate the application behavior during system sleep/wake power transitions.
  • Identify the issues causing the application to require a restart, lose data, or change state.
  • Implement application logic to respond to the power transition notifications and perform the necessary operations to survive the power transitions without requiring a restart or losing data. For a good user experience, handle the power transitions with no user interaction.

 

This item is part of a series of Knowledge Base items that discusses the concept of Application Power Management for Mobility; the other items in the series are as follows:

 

Source

 

For more complete information about compiler optimizations, see our Optimization Notice.