/// <summary> /// Allows an application to inform the system that it /// is in use, thereby preventing the system from entering /// the sleeping power state or turning off the display /// while the application is running. /// </summary> /// <param name="executionStateOptions">The thread's execution requirements.</param> /// <exception cref="Win32Exception">Thrown if the SetThreadExecutionState call fails.</exception> public static void SetThreadExecutionState(ExecutionStates executionStateOptions) { ExecutionStates ret = PowerManagementNativeMethods.SetThreadExecutionState(executionStateOptions); if (ret == ExecutionStates.None) { throw new Win32Exception(LocalizedMessages.PowerExecutionStateFailed); } }
/// <summary> /// Registers the application to receive power setting notifications /// for the specific power setting event. /// </summary> /// <param name="handle">Handle indicating where the power setting /// notifications are to be sent.</param> /// <param name="powerSetting">The GUID of the power setting for /// which notifications are to be sent.</param> /// <returns>Returns a notification handle for unregistering /// power notifications.</returns> internal static int RegisterPowerSettingNotification( IntPtr handle, Guid powerSetting) { int outHandle = PowerManagementNativeMethods.RegisterPowerSettingNotification( handle, ref powerSetting, 0); return(outHandle); }
GetSystemPowerCapabilities() { PowerManagementNativeMethods.SystemPowerCapabilities powerCap; uint retval = PowerManagementNativeMethods.CallNtPowerInformation( PowerManagementNativeMethods.PowerInformationLevel.SystemPowerCapabilities, IntPtr.Zero, 0, out powerCap, (UInt32)Marshal.SizeOf(typeof(PowerManagementNativeMethods.SystemPowerCapabilities)) ); if (retval == CoreNativeMethods.StatusAccessDenied) { throw new UnauthorizedAccessException(LocalizedMessages.PowerInsufficientAccessCapabilities); } return(powerCap); }
internal static PowerManagementNativeMethods.SystemBatteryState GetSystemBatteryState() { PowerManagementNativeMethods.SystemBatteryState batteryState; uint retval = PowerManagementNativeMethods.CallNtPowerInformation( PowerManagementNativeMethods.PowerInformationLevel.SystemBatteryState, IntPtr.Zero, 0, out batteryState, (UInt32)Marshal.SizeOf(typeof(PowerManagementNativeMethods.SystemBatteryState)) ); if (retval == CoreNativeMethods.StatusAccessDenied) { throw new UnauthorizedAccessException(LocalizedMessages.PowerInsufficientAccessBatteryState); } return(batteryState); }