fix:心跳机制

This commit is contained in:
2026-03-14 16:04:01 +08:00
parent d330d0bf26
commit 3354850216
+30 -16
View File
@@ -1252,27 +1252,41 @@ namespace Ink_Canvas
return; return;
} }
} }
if (isStartupComplete && (DateTime.Now - lastHeartbeat).TotalSeconds > 10) if (isStartupComplete)
{ {
LogHelper.NewLog("检测到主线程无响应,自动重启。"); var now = DateTime.Now;
SyncCrashActionFromSettings(); var sinceHeartbeat = now - lastHeartbeat;
if (CrashAction == CrashActionType.SilentRestart) var sinceStartupComplete = startupCompleteHeartbeat == DateTime.MinValue
? TimeSpan.Zero
: now - startupCompleteHeartbeat;
if (sinceStartupComplete.TotalSeconds < 30)
{ {
StartupCount.Increment(); return;
if (StartupCount.GetCount() >= 5) }
if (sinceHeartbeat.TotalSeconds > 10)
{
LogHelper.NewLog("检测到主线程无响应,自动重启。");
SyncCrashActionFromSettings();
if (CrashAction == CrashActionType.SilentRestart)
{ {
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error); StartupCount.Increment();
StartupCount.Reset(); if (StartupCount.GetCount() >= 5)
{
MessageBox.Show(Strings.GetString("Msg_RestartLimit"), Strings.GetString("Msg_RestartLimitTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
StartupCount.Reset();
Environment.Exit(1);
}
try
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(1); Environment.Exit(1);
} }
try
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(exePath);
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); }
Environment.Exit(1);
} }
} }
}, null, 0, 3000); }, null, 0, 3000);