From aab1e08729ecda31aa88fab2590abe2f78eab6f1 Mon Sep 17 00:00:00 2001 From: seerge Date: Wed, 5 Apr 2023 19:59:10 +0200 Subject: [PATCH] IsUsedGPU fix --- app/HardwareMonitor.cs | 36 ++++++++++++++++++++---------------- app/Settings.cs | 14 +++++++------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/HardwareMonitor.cs b/app/HardwareMonitor.cs index fb93dafe..2de42eb3 100644 --- a/app/HardwareMonitor.cs +++ b/app/HardwareMonitor.cs @@ -48,6 +48,20 @@ public static class HardwareMonitor return " Fan: " + Math.Min(Math.Round((float)fan/fanMax*100), 100).ToString() + "%"; // relatively to 6000 rpm } + private static int GetGpuUse() + { + try + { + int? gpuUse = GpuTemperatureProvider?.GetGpuUse(); + if (gpuUse is not null) return (int)gpuUse; + } + catch (Exception ex) + { + } + + return 0; + } + public static void ReadSensors() { batteryDischarge = -1; @@ -84,20 +98,8 @@ public static class HardwareMonitor if (gpuTemp is null || gpuTemp < 0) gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU); - try - { - gpuUse = GpuTemperatureProvider?.GetGpuUse(); - } catch (Exception ex) - { - gpuUse = -1; - Debug.WriteLine(ex.ToString()); - } - - if (gpuUse is not null && gpuUse >= 0) - { - gpuUsage.Add((int)gpuUse); - if (gpuUsage.Count > 3) gpuUsage.RemoveAt(0); - } + gpuUsage.Add(GetGpuUse()); + if (gpuUsage.Count > 3) gpuUsage.RemoveAt(0); try { @@ -114,8 +116,10 @@ public static class HardwareMonitor public static bool IsUsedGPU(int threshold = 50) { - if (gpuUsage.Count < 2) return false; - return (gpuUsage.Average() > threshold); + if (GetGpuUse() > threshold) + return true; + else + return (gpuUsage.Average() > threshold); } public static void RecreateGpuTemperatureProviderWithDelay() { diff --git a/app/Settings.cs b/app/Settings.cs index 104a1b65..ab553674 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1064,18 +1064,19 @@ namespace GHelper if (eco == 1) if ((GpuAuto && Plugged == PowerLineStatus.Online) || (ForceGPU && GpuMode == ASUSWmi.GPUModeStandard)) { - if (HardwareMonitor.IsUsedGPU()) - { - DialogResult dialogResult = MessageBox.Show("Your dGPU seem to be in heavy use, disable it?", "Eco Mode", MessageBoxButtons.YesNo); - if (dialogResult == DialogResult.No) return false; - } - SetEcoGPU(0); return true; } if (eco == 0) if ((GpuAuto && Plugged != PowerLineStatus.Online) || (ForceGPU && GpuMode == ASUSWmi.GPUModeEco)) { + + if (HardwareMonitor.IsUsedGPU()) + { + DialogResult dialogResult = MessageBox.Show("Your dGPU seem to be in heavy use, disable it?", "Eco Mode", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.No) return false; + } + SetEcoGPU(1); return true; } @@ -1142,7 +1143,6 @@ namespace GHelper public void SetEcoGPU(int eco) { - ButtonEnabled(buttonOptimized, false); ButtonEnabled(buttonEco, false); ButtonEnabled(buttonStandard, false);