問題は、たとえば temperature_label が 47 にあり、label8 も 47 にあることです。
次のイテレーションでは、温度ラベルが 42 に下がると言って、次のイテレーション label8 も 42 になるようにします。temperature_label が 47 を超える場合にのみ、再度 label8 を更新します。
したがって、 temperature_label が同じ値の場合、変更がないか、最後の値を超えている場合は label8 を更新します。
温度ラベルが最後の最高値を下回っている場合、ラベル8を更新しないでください。最後の最高値は、温度ラベルが70で、現在は60で長時間ラベル8を更新しないことを意味しますが、71を超える場合はラベル8を71に更新し、71を維持して更新しますlabel8 は、 temperature_label がそれを上回った場合のみ。
しかし、コードが変更されたため、温度ラベルが最後の値から下がったとしても、label8 が更新されます。
今のように最後の値で label8 を更新したくありませんが、最後の最高値です。そして、最後の最高値がそれより上に変更された場合にのみ、label8 を更新します。
現在の値ではなく、temperature_label と label8 が同じ値になる可能性がありますが、temperature_label ドロップダウンの場合、label8 はそうではありません。そして、もし temperature_lable が最後の最高値から上昇したら、再度 label8 を更新します。これが私が必要とする条件です。
コード:
行で例外エラーが発生しています: if (UpdatingLabel(sensor.Value.ToString(), temperature_label.Text.Substring(0, temperature_label.Text.Length - 1)))
例外は: ArgumentOutOfRangeException:
長さを 0 未満にすることはできません。パラメータ名: 長さ
System.ArgumentOutOfRangeException was unhandled
  Message=Length cannot be less than zero.
Parameter name: length
  Source=mscorlib
  ParamName=length
  StackTrace:
       at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
       at System.String.Substring(Int32 startIndex, Int32 length)
       at Bursa.Form1.timer2_Tick(Object sender, EventArgs e) in D:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Form1.cs:line 369
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Bursa.Program.Main() in D:\C-Sharp\HardwareMonitoring\HardwareMonitoring\Hardwaremonitoring\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
あなたのコードに従って行った変更後のコード:
private void timer2_Tick(object sender, EventArgs e)
        {
            Computer computer = new Computer();
            computer.Open();
            computer.GPUEnabled = true;
            foreach (var hardwareItem in computer.Hardware)
            {
                if (hardwareItem.HardwareType == HardwareType.GpuNvidia)
                {
                    foreach (var sensor in hardwareItem.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Temperature)
                        {
                            sensor.Hardware.Update();
                            if (UpdatingLabel(sensor.Value.ToString(), temperature_label.Text.Substring(0, temperature_label.Text.Length - 1)))
                                label8.Text = temperature_label.Text;
                            temperature_label.Text = sensor.Value.ToString() + "c";
                            label8.Visible = true;
                            int t = temperature_label.Text.Length;
                            if (t > 3)
                            {
                                temperature_label.Location = new Point(238, 200);
                            }
                            timer2.Interval = 1000;
                            if (sensor.Value > 90)
                            {
                                Logger.Write("The current temperature is ===> " + sensor.Value);
                                button1.Enabled = true;
                            }
                            this.Select();
                        }
                    }
                }
            }     
        }
        private bool UpdatingLabel(string newVal, string oldVal)
        {
            int intVal1 = int.Parse(newVal);
            int intVal2 = int.Parse(oldVal);
            if (intVal1 > intVal2)
                return true;
            else
                return false;
        }
    }