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