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: