精确优化程序关闭问题

This commit is contained in:
GukSang.Jin
2026-02-04 18:29:56 +08:00
parent 2ba1f3dae7
commit 17e9cea482
4 changed files with 263 additions and 70 deletions

View File

@@ -41,6 +41,12 @@ namespace 全自动水压检测仪
private void UpdateTimer_Tick(object sender, EventArgs e)
{
// 检查窗体状态
if (this.IsDisposed || !this.IsHandleCreated)
{
return;
}
try
{
UpdateStatusDisplay();
@@ -111,8 +117,20 @@ namespace 全自动水压检测仪
private void StatusSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
_updateTimer?.Stop();
_updateTimer?.Dispose();
try
{
if (_updateTimer != null)
{
_updateTimer.Stop();
_updateTimer.Tick -= UpdateTimer_Tick;
_updateTimer.Dispose();
_updateTimer = null;
}
}
catch (Exception ex)
{
Debug.WriteLine($"释放定时器资源失败: {ex.Message}");
}
}
private void uiButton_Close_Click(object sender, EventArgs e)