I have a very long running syncronization task that cannot be interrupted by the screen saver or aggressive power saving modes. I want to make a single api call to stop power save mode and then restore it once the task is done.
The following code is peaced together from various other posts but it has no effect on XP's power management settings. What am I doing wrong? TIA!
Private Declare Function SetThreadExecutionState Lib "kernel32" (ByVal esFlags As Long) As Long
Public Enum EXECUTION_STATE As Integer
ES_CONTINUOUS = &H80000000
ES_DISPLAY_REQUIRED = &H2
ES_SYSTEM_REQUIRED = &H1
ES_AWAYMODE_REQUIRED = &H40
End Enum
Public Shared Sub PowerSaveOff()
SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED Or EXECUTION_STATE.ES_CONTINUOUS)
End Sub
Public Shared Sub PowerSaveOn()
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS)
End Sub
Here are the systems screensaver and powermode settings: alt text http://img87.imageshack.us/img87/1600/25251376.jpg alt text http://img403.imageshack.us/img403/8145/73347627.jpg
I added
EXECUTION_STATE.ES_SYSTEM_REQUIRED
, which "Forces the system to be in the working state by resetting the system idle timer," and prevents the system from entering a power saving state. I also changed the API calling convention to useEXECUTION_STATE
, wrapped everything in a simple utility class with some documentation.