private void ApplyPlanByGuid(Guid guid) { try { if (isInitialized == false) { userCurrentPowerPlan = PowerManagementHelper.CurrentPlan; isInitialized = true; } if (PowerManagementHelper.Set(guid)) { powerPlanChanged = true; var powerPlanFriendlyName = PowerManagementHelper.CurrentPlanFriendlyName; logger.WriteInfo($"Setup power plan (GUID: {guid} FriendlyName: {powerPlanFriendlyName})"); } else { logger.WriteLineError($"Cannot setup power plan (GUID: {guid})"); } } catch (Exception ex) { logger.WriteLineError($"Cannot setup power plan (GUID: {guid}, error message: {ex.Message})"); } }
internal void ApplyUserPowerPlan() { if (powerPlanChanged && RuntimeInformation.IsWindows()) { try { if (userCurrentPowerPlan != null && PowerManagementHelper.Set(userCurrentPowerPlan.Value)) { powerPlanChanged = false; var powerPlanFriendlyName = PowerManagementHelper.CurrentPlanFriendlyName; logger.WriteLineInfo($"Successfully reverted power plan (GUID: {userCurrentPowerPlan.Value} FriendlyName: {powerPlanFriendlyName})"); } } catch (Exception ex) { logger.WriteLineError($"Cannot revert power plan (error message: {ex.Message})"); } } }
public static void PreventSleep(this Application application, Boolean includeDisplay) { PowerManagementHelper.PreventSleep(includeDisplay); }