fix: 修复长时间运行后的卡死问题

This commit is contained in:
2026-01-19 20:56:07 +08:00
parent d421b9b72b
commit 37bef1ead3
3 changed files with 132 additions and 71 deletions

View File

@@ -412,7 +412,7 @@ namespace TimerApp
{
if (InvokeRequired)
{
Invoke(new Action<object?, EventArgs>(Monitor_StateChanged), sender, e);
BeginInvoke(new Action<object?, EventArgs>(Monitor_StateChanged), sender, e);
return;
}
UpdateStatusUI();
@@ -461,19 +461,25 @@ namespace TimerApp
{
if (InvokeRequired)
{
Invoke(new Action<object?, TimeSpan>(Monitor_WorkProgressChanged), sender, remaining);
BeginInvoke(new Action<object?, TimeSpan>(Monitor_WorkProgressChanged), sender, remaining);
return;
}
lblTimeLeft.Text = $"{remaining.Minutes:D2}:{remaining.Seconds:D2}";
// Update tray tooltip
string newText;
if (remaining.TotalMinutes < 1)
{
notifyIcon1.Text = $"即将休息: {remaining.Seconds}秒";
newText = $"即将休息: {remaining.Seconds}秒";
}
else
{
notifyIcon1.Text = $"工作中: 剩余 {remaining.Minutes} 分钟";
newText = $"工作中: 剩余 {remaining.Minutes} 分钟";
}
if (notifyIcon1.Text != newText)
{
notifyIcon1.Text = newText;
}
}
@@ -481,7 +487,7 @@ namespace TimerApp
{
if (InvokeRequired)
{
Invoke(new Action<object?, EventArgs>(Monitor_RestStarted), sender, e);
BeginInvoke(new Action<object?, EventArgs>(Monitor_RestStarted), sender, e);
return;
}
@@ -503,6 +509,12 @@ namespace TimerApp
private void Monitor_RestProgressChanged(object? sender, TimeSpan remaining)
{
if (InvokeRequired)
{
BeginInvoke(new Action<object?, TimeSpan>(Monitor_RestProgressChanged), sender, remaining);
return;
}
if (_restForm != null && !_restForm.IsDisposed && _restForm.Visible)
{
_restForm.UpdateTime(remaining);
@@ -513,7 +525,7 @@ namespace TimerApp
{
if (InvokeRequired)
{
Invoke(new Action<object?, EventArgs>(Monitor_RestEnded), sender, e);
BeginInvoke(new Action<object?, EventArgs>(Monitor_RestEnded), sender, e);
return;
}
@@ -568,9 +580,15 @@ namespace TimerApp
private void ShowForm()
{
if (this.IsDisposed) return;
this.Show();
this.WindowState = FormWindowState.Normal;
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
this.Activate();
this.BringToFront();
}
public void ActivateFromExternal()