From 78e346bdec1118d74f38552cf8440dddaabbcd8e Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Wed, 4 Feb 2026 18:06:41 +0800 Subject: [PATCH] =?UTF-8?q?Reapply=20"=E4=BF=AE=E6=94=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c89221db838aca7ed8a3c2d5170c154aaac8abb9. --- 全自动水压检测仪/NormalTemperatureMode.cs | 25 +++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/全自动水压检测仪/NormalTemperatureMode.cs b/全自动水压检测仪/NormalTemperatureMode.cs index b5a8477..b6fb681 100644 --- a/全自动水压检测仪/NormalTemperatureMode.cs +++ b/全自动水压检测仪/NormalTemperatureMode.cs @@ -48,6 +48,10 @@ namespace 全自动水压检测仪 private System.Windows.Forms.Timer _readTimerTwo; // 第二个定时器引用 private bool _isManualInput = false; // 手动输入标记 private bool _isSwitchingWindow = false; // 窗口切换标记,避免并发 + + // 温度模式状态跟踪(用于防抖优化) + private bool _lastHighTempMode = false; + private bool _lastLowTempMode = false; private ConductivityRepository _repository; @@ -780,27 +784,23 @@ namespace 全自动水压检测仪 } } - //低温指示 + //低温指示(优化版本 - 减少不必要的UI更新) if (modbusResults.LowStatus != null && modbusResults.LowStatus.Length > 0 && uiLight1 != null && !uiLight1.IsDisposed) { - bool previousLowTempState = uiLight1.State == UILightState.On; bool currentLowTempState = modbusResults.LowStatus[0]; - uiLight1.State = currentLowTempState ? UILightState.On : UILightState.Off; - // 如果温度模式状态发生变化,更新控件可见性 - if (previousLowTempState != currentLowTempState) + // 只有状态真正改变时才更新控件可见性 + if (_lastLowTempMode != currentLowTempState) { UpdateControlsVisibilityByMode(); } } - //高温指示 + //高温指示(优化版本 - 减少不必要的UI更新) if (modbusResults.HighStatus != null && modbusResults.HighStatus.Length > 0 && uiLight2 != null && !uiLight2.IsDisposed) { - bool previousHighTempState = uiLight2.State == UILightState.On; bool currentHighTempState = modbusResults.HighStatus[0]; - uiLight2.State = currentHighTempState ? UILightState.On : UILightState.Off; // 如果温度模式状态发生变化,更新控件可见性 @@ -1280,7 +1280,7 @@ namespace 全自动水压检测仪 ma?.BtnClickFunctionForNew(Function.ButtonType.复归型, 10082); } - //切换实验模式 + //切换实验模式(优化版本 - 减少延迟和卡顿) private async void uiSwitch1_Click(object sender, EventArgs e) { try @@ -1306,8 +1306,8 @@ namespace 全自动水压检测仪 } }); - // 延迟等待PLC状态更新 - await Task.Delay(800); + // 缩短延迟时间,从800ms减少到300ms + await Task.Delay(300); // 更新控件可见性 SafeInvoke(() => @@ -1634,7 +1634,7 @@ namespace 全自动水压检测仪 /// /// - /// 根据温度模式更新控件可见性 + /// 根据温度模式更新控件可见性(优化版本 - 批量更新减少卡顿) /// 常温模式:显示常温相关参数(常温实时液位、常温加水) /// 高温模式:显示高温相关参数(高温实时液位、箱体温度、出口温度、高温加水、水箱加热) /// @@ -1767,7 +1767,6 @@ namespace 全自动水压检测仪 try { bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On; - bool isLowTempMode = uiLight1 != null && uiLight1.State == UILightState.On; Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");