Exemplo n.º 1
0
        /// <summary>
        /// Suspends the system by shutting power down.
        /// </summary>
        /// <param name="hibernate">If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.</param>
        /// <param name="forceCritical">don't take an attantion on this parameter. He does nothing.</param>
        /// <param name="disableWakeEvent">If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.</param>
        public void SuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent)
        {
            uint result = PowerManagementConfiguration.SetSuspendState(hibernate, forceCritical, disableWakeEvent);

            if (result == 0)
            {
                throw new Win32Exception();
            }
        }
        /// <summary>
        /// https://docs.microsoft.com/en-us/windows/win32/api/powrprof/nf-powrprof-setsuspendstate
        /// If the function succeeds, the return value is nonzero.
        /// If the function fails, the return value is zero.To get extended error information, call GetLastError.
        /// </summary>
        /// <param name="hibernate">If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.</param>
        /// <param name="force">This parameter has no effect.</param>
        /// <param name="wakeupEventsDisabled">If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.</param>
        public void SuspendState(bool hibernate, bool force, bool wakeupEventsDisabled)
        {
            var result = PowerManagementConfiguration.SetSuspendState(hibernate, force, wakeupEventsDisabled);

            if (result == 0)
            {
                throw new Win32Exception("Something went wrong.");
            }
        }