public void ClearPowerManagementOverrides() { var result = WindowsPowerManagementApi.SetThreadExecutionState(WindowsPowerManagementApi.EXECUTION_STATE.ES_CONTINUOUS); if (result == 0) { throw new Win32Exception(); } }
public void PreventSleep() { var result = WindowsPowerManagementApi.SetThreadExecutionState( WindowsPowerManagementApi.EXECUTION_STATE.ES_SYSTEM_REQUIRED | WindowsPowerManagementApi.EXECUTION_STATE.ES_CONTINUOUS); if (result == 0) { throw new Win32Exception(); } }