improve:崩溃重启
This commit is contained in:
@@ -1195,6 +1195,7 @@ namespace Ink_Canvas
|
||||
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>
|
||||
/// 启动并管理应用的心跳与守护检查定时器,监测启动阶段与主线程是否无响应,并在符合配置的情况下尝试静默重启应用。
|
||||
@@ -1218,6 +1219,8 @@ namespace Ink_Canvas
|
||||
|
||||
watchdogTimer = new Timer(_ =>
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
if (IsOobeShowing)
|
||||
return;
|
||||
|
||||
@@ -1226,8 +1229,8 @@ namespace Ink_Canvas
|
||||
DateTime startTime = _isSplashScreenShown && splashScreenStartTime != DateTime.MinValue
|
||||
? splashScreenStartTime
|
||||
: appStartupStartTime;
|
||||
TimeSpan elapsedSinceStart = DateTime.Now - startTime;
|
||||
if (elapsedSinceStart.TotalMinutes >= 2)
|
||||
TimeSpan elapsedSinceStart = now - startTime;
|
||||
if (elapsedSinceStart >= StartupTimeout)
|
||||
{
|
||||
string timeType = _isSplashScreenShown ? "启动画面已显示" : "应用启动开始";
|
||||
LogHelper.WriteLogToFile($"检测到启动假死:{timeType}{elapsedSinceStart.TotalMinutes:F2}分钟,但未收到启动完成心跳,自动重启。", LogHelper.LogType.Error);
|
||||
@@ -1253,8 +1256,11 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
if (isStartupComplete && (DateTime.Now - lastHeartbeat).TotalSeconds > 10)
|
||||
if (isStartupComplete && (now - lastHeartbeat).TotalSeconds > 10)
|
||||
{
|
||||
if (appStartupStartTime != DateTime.MinValue && (now - appStartupStartTime) < StartupTimeout)
|
||||
return;
|
||||
|
||||
LogHelper.NewLog("检测到主线程无响应,自动重启。");
|
||||
SyncCrashActionFromSettings();
|
||||
if (CrashAction == CrashActionType.SilentRestart)
|
||||
|
||||
Reference in New Issue
Block a user