Saturday, September 08, 2012

How to: make sure windows doesn't go to sleep/hibernate

I'm currently working on support tools for an embedded system. When loading new software or loggning information from the system it takes a long time. Got feedback from the users that the tools act strange when their computers went to sleep and the they activate  the computer again. No errors indicated in the tools but it the log files look strange.

The problem can be solved in two ways:

  1. Turn off the sleep/hibernate in windows.
    1. Control panel
    2. System
    3. Power options
    4. Plan
    5. Put computer to sleep never.

      This is an easy fix but it is impossible to ensure that the users do this, and when they run into this problem it's already to late.
  2. Make sure the application tells windows it is going to run a long process, and that the user needs to wait for it to complete.

    See Stack Overflow question. http://stackoverflow.com/questions/629240/prevent-windows-from-going-into-sleep-when-my-program-is-running

    On XP See: WM_POWERBROADCAST

    On Vista and Windows 7 See: SetThreadExecutionState

    This is the path I think is correct by telling the operating system what the application is doing it supports the application and user does not have to do anything to get the correct behavior when logging or uploading software to the system.

No comments: