I have a tablet that runs a virtual dash for my drag car. While the software is running, I want to prevent any sleep mode, so I added this code to the top of my vb and I call the function "PowerSaveOff" as soon as the form loads. In .Net 3.5, the MDA for PInvoke is disabled by default, but in 4.0 I get the error for stack imbalance. Any ideas how to correct this properly rather than using a band-aid and just disabling the exception?
Code:
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_SYSTEM_REQUIRED Or EXECUTION_STATE.ES_DISPLAY_REQUIRED Or EXECUTION_STATE.ES_CONTINUOUS)
End Sub
Public Shared Sub PowerSaveOn()
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS)
End Sub