private void HibernateFileManagement(bool isReserve) { var bufferSize = Marshal.SizeOf(typeof(bool)); var inputBuffer = Marshal.AllocCoTaskMem(bufferSize); var bytes = isReserve.ToByte(); try { var result = PowerManagementNative .CallNtPowerInformation( PowerInformationLevel.SystemReserveHiberFile, inputBuffer, (uint)1, IntPtr.Zero, 0); if (!this.IsSuccess(result)) { var error = Marshal.GetLastWin32Error(); throw new Exception($"CallNtPowerInformation executed with an error {error}"); } } finally { Marshal.FreeCoTaskMem(inputBuffer); } }
private long GetPowerInformation(PowerInformationLevel informationLevel) { var result = PowerManagementNative.CallNtPowerInformation( informationLevel, IntPtr.Zero, 0, out IntPtr time, (uint)Marshal.SizeOf(typeof(long))); return(this.IsSuccess(result) ? time.ToInt64() : 0); }
public SystemPowerInformation GetSystemPowerInformation() { var result = PowerManagementNative.CallNtPowerInformation( PowerInformationLevel.SystemPowerInformation, IntPtr.Zero, 0, out SystemPowerInformation systemPowerInfo, (uint)Marshal.SizeOf(typeof(SystemBatteryState))); return(this.IsSuccess(result) ? systemPowerInfo : new SystemPowerInformation()); }
public void PutComputerToHibernate() { PowerManagementNative.SetSuspendState(true, true, true); }
public void PutComputerToSleep() { PowerManagementNative.SetSuspendState(false, true, true); }