From 14eedca93981a72a16443d561700fd9e2d2f19bc Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sun, 24 Aug 2025 01:46:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=97=B6=E9=97=B4=E6=88=B3=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/App.xaml.cs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index 0f50976a..3a953b57 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -331,7 +331,8 @@ namespace Ink_Canvas private void CurrentDomain_ProcessExit(object sender, EventArgs e) { TimeSpan runDuration = DateTime.Now - appStartTime; - WriteCrashLog($"应用程序退出,运行时长: {runDuration}"); + string durationText = FormatTimeSpan(runDuration); + WriteCrashLog($"应用程序退出,运行时长: {durationText}"); // 如果有最后错误消息,记录到日志 if (!string.IsNullOrEmpty(lastErrorMessage)) @@ -340,6 +341,27 @@ namespace Ink_Canvas } } + // 新增:格式化时间跨度 + private static string FormatTimeSpan(TimeSpan timeSpan) + { + if (timeSpan.TotalDays >= 1) + { + return $"{timeSpan.Days}天 {timeSpan.Hours}小时 {timeSpan.Minutes}分钟"; + } + else if (timeSpan.TotalHours >= 1) + { + return $"{timeSpan.Hours}小时 {timeSpan.Minutes}分钟"; + } + else if (timeSpan.TotalMinutes >= 1) + { + return $"{timeSpan.Minutes}分钟 {timeSpan.Seconds}秒"; + } + else + { + return $"{timeSpan.Seconds}秒"; + } + } + // 新增:记录崩溃日志 private static void WriteCrashLog(string message) { @@ -356,7 +378,7 @@ namespace Ink_Canvas // 收集系统状态信息 string memoryUsage = (Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024)) + " MB"; string cpuTime = Process.GetCurrentProcess().TotalProcessorTime.ToString(); - string processUptime = (DateTime.Now - Process.GetCurrentProcess().StartTime).ToString(); + string processUptime = FormatTimeSpan(DateTime.Now - Process.GetCurrentProcess().StartTime); string statusInfo = $"[内存: {memoryUsage}, CPU时间: {cpuTime}, 运行时长: {processUptime}]"; @@ -436,6 +458,9 @@ namespace Ink_Canvas void App_Startup(object sender, StartupEventArgs e) { + // 初始化应用启动时间 + appStartTime = DateTime.Now; + /*if (!StoreHelper.IsStoreApp) */ RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;