improve:计时器

This commit is contained in:
2025-10-12 16:08:36 +08:00
parent 339ebb862e
commit 869dd045af
3 changed files with 58 additions and 2 deletions
@@ -31,6 +31,8 @@ namespace Ink_Canvas
updateTimer = new System.Timers.Timer(100);
updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.Start();
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
}
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
@@ -70,6 +72,14 @@ namespace Ink_Canvas
SetDigitDisplay("FullSecond2Display", seconds % 10);
}
}
private void ParentWindow_TimerCompleted(object sender, EventArgs e)
{
Application.Current.Dispatcher.Invoke(() =>
{
this.Close();
});
}
private void SetDigitDisplay(string pathName, int digit)
{
@@ -116,6 +126,11 @@ namespace Ink_Canvas
protected override void OnClosed(EventArgs e)
{
if (parentWindow != null)
{
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
}
// 清理资源
if (updateTimer != null)
{