From 4c323ab71a4a4acc5f28b3d559d487b8f092549a Mon Sep 17 00:00:00 2001 From: Den Delimarsky <1389609+dend@users.noreply.github.com> Date: Wed, 30 Jun 2021 04:04:31 -0700 Subject: [PATCH] [Hotfix] PowerToys Awake - fixing CPU usage (#11978) * Change how background threads operate This should reduce CPU usage. * Well there is just no need for the console here * Need to keep the full name sanitized --- src/modules/awake/Awake/Core/APIHelper.cs | 11 ++++------- src/modules/awake/Awake/Program.cs | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/modules/awake/Awake/Core/APIHelper.cs b/src/modules/awake/Awake/Core/APIHelper.cs index ffa242a864..da128f639b 100644 --- a/src/modules/awake/Awake/Core/APIHelper.cs +++ b/src/modules/awake/Awake/Core/APIHelper.cs @@ -184,13 +184,10 @@ namespace Awake.Core if (success) { _log.Info($"Initiated indefinite keep awake in background thread: {GetCurrentThreadId()}. Screen on: {keepDisplayOn}"); - while (true) - { - if (_threadToken.IsCancellationRequested) - { - _threadToken.ThrowIfCancellationRequested(); - } - } + + WaitHandle.WaitAny(new[] { _threadToken.WaitHandle }); + + return success; } else { diff --git a/src/modules/awake/Awake/Program.cs b/src/modules/awake/Awake/Program.cs index 9087ad848e..1cb660356c 100644 --- a/src/modules/awake/Awake/Program.cs +++ b/src/modules/awake/Awake/Program.cs @@ -28,6 +28,7 @@ namespace Awake { private static Mutex? _mutex = null; private const string AppName = "Awake"; + private const string FullAppName = "PowerToys " + AppName; private static FileSystemWatcher? _watcher = null; private static SettingsUtils? _settingsUtils = null; @@ -127,7 +128,6 @@ namespace Awake private static void ForceExit(string message, int exitCode) { _log.Info(message); - Console.ReadKey(); Environment.Exit(exitCode); } @@ -180,7 +180,7 @@ namespace Awake .Select(e => e.EventArgs) .Subscribe(HandleAwakeConfigChange); - TrayHelper.SetTray(AppName, new AwakeSettings()); + TrayHelper.SetTray(FullAppName, new AwakeSettings()); // Initially the file might not be updated, so we need to start processing // settings right away.