public static void restoreSystemSleepState() { try { WindowsNativeMethods.SetThreadExecutionState(WindowsNativeMethods.EXECUTION_STATE.ES_CONTINUOUS); } catch (DllNotFoundException dnte) { } catch (EntryPointNotFoundException enfe) { } }
public static void PreventSystemFromSleeping() { try { fPreviousExecutionState = WindowsNativeMethods.SetThreadExecutionState(WindowsNativeMethods.EXECUTION_STATE.ES_CONTINUOUS | WindowsNativeMethods.EXECUTION_STATE.ES_AWAYMODE_REQUIRED | WindowsNativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED); } catch (DllNotFoundException dnte) { } catch (EntryPointNotFoundException enfe) { } }