diff --git a/CommonHelpers/Instance.cs b/CommonHelpers/Instance.cs index 8dab762..efcc111 100644 --- a/CommonHelpers/Instance.cs +++ b/CommonHelpers/Instance.cs @@ -105,7 +105,7 @@ namespace CommonHelpers } } - public static T WithGlobalMutex(int timeoutMs, Func func) + public static T? WithGlobalMutex(int timeoutMs, Func func) { var mutex = WaitGlobalMutex(timeoutMs); if (mutex is null) diff --git a/CommonHelpers/RTSS.cs b/CommonHelpers/RTSS.cs index 94f2b84..a5f27a4 100644 --- a/CommonHelpers/RTSS.cs +++ b/CommonHelpers/RTSS.cs @@ -10,12 +10,13 @@ namespace CommonHelpers return IsOSDForeground(out _); } - public static bool IsOSDForeground(out int? processId) + public static bool IsOSDForeground(out int processId) { try { - processId = (int?)GetTopLevelProcessId(); - if (processId is null) + var id = GetTopLevelProcessId(); + processId = (int)id.GetValueOrDefault(0); + if (id is null) return false; foreach (var app in OSD.GetAppEntries(AppFlags.MASK)) @@ -28,7 +29,7 @@ namespace CommonHelpers } catch { - processId = null; + processId = 0; return false; } } diff --git a/PowerControl/Menu/MenuItemWithOptions.cs b/PowerControl/Menu/MenuItemWithOptions.cs index af8256f..2818979 100644 --- a/PowerControl/Menu/MenuItemWithOptions.cs +++ b/PowerControl/Menu/MenuItemWithOptions.cs @@ -8,10 +8,10 @@ namespace PowerControl.Menu public int ApplyDelay { get; set; } public bool CycleOptions { get; set; } = true; - public Func? CurrentValue { get; set; } - public Func? OptionsValues { get; set; } - public Func? ApplyValue { get; set; } - public Func? ResetValue { get; set; } + public Func? CurrentValue { get; set; } + public Func? OptionsValues { get; set; } + public Func? ApplyValue { get; set; } + public Func? ResetValue { get; set; } private System.Windows.Forms.Timer delayTimer = new System.Windows.Forms.Timer(); private ToolStripMenuItem toolStripItem = new ToolStripMenuItem(); diff --git a/PowerControl/Options/GPUFrequency.cs b/PowerControl/Options/GPUFrequency.cs index 7dc5465..df31971 100644 --- a/PowerControl/Options/GPUFrequency.cs +++ b/PowerControl/Options/GPUFrequency.cs @@ -34,7 +34,7 @@ namespace PowerControl.Options return selected; } - sd.HardMinGfxClock = uint.Parse(selected.ToString().Replace("MHz", "")); + sd.HardMinGfxClock = uint.Parse(selected.ToString()?.Replace("MHz", "") ?? "200"); return selected; } }); diff --git a/PowerControl/Options/SMT.cs b/PowerControl/Options/SMT.cs index 4e24f8b..1808791 100644 --- a/PowerControl/Options/SMT.cs +++ b/PowerControl/Options/SMT.cs @@ -18,7 +18,7 @@ namespace PowerControl.Options if (!ProcessorCores.HasSMTThreads()) return null; - return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; + return ProcessorCores.IsUsingSMT(processId) ? "Yes" : "No"; }, ApplyValue = delegate (object selected) { @@ -27,9 +27,9 @@ namespace PowerControl.Options if (!ProcessorCores.HasSMTThreads()) return null; - ProcessorCores.SetProcessSMT(processId.Value, selected.ToString() == "Yes"); + ProcessorCores.SetProcessSMT(processId, selected.ToString() == "Yes"); - return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No"; + return ProcessorCores.IsUsingSMT(processId) ? "Yes" : "No"; } }; } diff --git a/PowerControl/Options/TDP.cs b/PowerControl/Options/TDP.cs index 42647dc..f3ca5f3 100644 --- a/PowerControl/Options/TDP.cs +++ b/PowerControl/Options/TDP.cs @@ -21,7 +21,11 @@ namespace PowerControl.Options ) return null; - uint mW = uint.Parse(selected.ToString().Replace("W", "")) * 1000; + var selectedText = selected.ToString(); + if (selectedText is null) + return null; + + uint mW = uint.Parse(selectedText.Replace("W", "")) * 1000; if (VangoghGPU.IsSupported) {