Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions Ink Canvas/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
LogHelper.WriteLogToFile($"App | 清理更新标记文件失败: {ex.Message}", LogHelper.LogType.Warning);
}

Task.Run(async () =>

Check warning on line 834 in Ink Canvas/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Build & Package

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
{
try
{
Expand Down Expand Up @@ -1117,7 +1117,7 @@
{
LogHelper.WriteLogToFile($"App | 处理启动URI参数: {startupUriArg}", LogHelper.LogType.Event);
// 延迟一点执行,确保窗口初始化完成
Task.Delay(1000).ContinueWith(_ =>

Check warning on line 1120 in Ink Canvas/App.xaml.cs

View workflow job for this annotation

GitHub Actions / Build & Package

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
{
mainWindow.Dispatcher.Invoke(() =>
{
Expand Down Expand Up @@ -1195,7 +1195,6 @@
private static DateTime startupCompleteHeartbeat = DateTime.MinValue;
private static DateTime splashScreenStartTime = DateTime.MinValue;
private static DateTime appStartupStartTime = DateTime.MinValue;
private static readonly TimeSpan StartupTimeout = TimeSpan.FromMinutes(2);

/// <summary>
/// 启动并管理应用的心跳与守护检查定时器,监测启动阶段与主线程是否无响应,并在符合配置的情况下尝试静默重启应用。
Expand All @@ -1219,8 +1218,6 @@

watchdogTimer = new Timer(_ =>
{
var now = DateTime.Now;

if (IsOobeShowing)
return;

Expand All @@ -1229,8 +1226,8 @@
DateTime startTime = _isSplashScreenShown && splashScreenStartTime != DateTime.MinValue
? splashScreenStartTime
: appStartupStartTime;
TimeSpan elapsedSinceStart = now - startTime;
if (elapsedSinceStart >= StartupTimeout)
TimeSpan elapsedSinceStart = DateTime.Now - startTime;
if (elapsedSinceStart.TotalMinutes >= 2)
{
string timeType = _isSplashScreenShown ? "启动画面已显示" : "应用启动开始";
LogHelper.WriteLogToFile($"检测到启动假死:{timeType}{elapsedSinceStart.TotalMinutes:F2}分钟,但未收到启动完成心跳,自动重启。", LogHelper.LogType.Error);
Expand All @@ -1255,12 +1252,8 @@
return;
}
}

if (isStartupComplete && (now - lastHeartbeat).TotalSeconds > 10)
if (isStartupComplete && (DateTime.Now - lastHeartbeat).TotalSeconds > 10)
{
Comment on lines +1255 to 1256
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep startup grace period before watchdog restarts

This restart condition now triggers immediately after isStartupComplete once heartbeat lag exceeds 10s, but the previous guard that skipped watchdog restarts during the first 2 minutes after process start was removed. On slower machines or heavy startup paths, lastHeartbeat can still be stale when startup just finished, so this can cause false-positive “main thread unresponsive” restarts and restart loops right after launch. Please restore the startup grace check (or equivalent) before applying the 10s heartbeat rule.

Useful? React with 👍 / 👎.

if (appStartupStartTime != DateTime.MinValue && (now - appStartupStartTime) < StartupTimeout)
return;

LogHelper.NewLog("检测到主线程无响应,自动重启。");
SyncCrashActionFromSettings();
if (CrashAction == CrashActionType.SilentRestart)
Expand Down Expand Up @@ -1468,4 +1461,4 @@
}
}
}
}
}
Loading
Loading