fix: 修复长时间运行后随机闪退的后台线程未处理异常 - #638
Draft
fplj-fplj wants to merge 1 commit into
Draft
Conversation
运行 20 分钟至数小时后出现闪退,通常不是启动即崩,而是后台线程 (SystemEvents / System.Threading.Timer / System.Timers.Timer)抛出 未处理异常导致进程直接退出。本次针对以下路径做防御性修复: - SystemEvents.UserPreferenceChanged / DisplaySettingsChanged 在系统 事件专用线程触发,原实现直接访问 WPF UI 对象,跨线程访问会抛 InvalidOperationException 并终止进程;现封送到主线程 Dispatcher, 并在 Window_Closed 取消订阅 UserPreferenceChanged。 - HandleFloatingBarRecovery 的 DelayAction 回调在 Timer 线程直接 执行 ViewboxFloatingBarMarginAnimation,现改为仅负责 Dispatcher.BeginInvoke 封送。 - 看门狗 watchdogTimer 回调整体增加 try/catch,避免看门狗自身异常 成为闪退源。 - WindowOverviewModel.WindowsUpdated、SystemEventMonitor 的 ForegroundWindowChanged/ProcessChanged、RulesetService 的 StatusUpdated 等事件订阅者异常加兜底,避免在 Timer 线程上冒泡。 - DelayAction / TimerTrigger / 时间与日期显示定时器回调增加异常保护。 由于无可测试环境,尚未测试。
Member
Member
|
该问题不清楚,此pr暂不受理(在我学校的设备上从未出现此问题) |
CJKmkp
marked this pull request as draft
August 22, 2026 08:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
项目在使用 20 分钟至数小时后出现闪退。此类“运行一段时间后才闪退”通常不是启动即崩,而是后台线程抛出未处理异常导致进程直接退出。
修复内容
针对以下后台线程未处理异常 / 跨线程访问 UI 的路径做防御性修复:
SystemEvents.UserPreferenceChanged/DisplaySettingsChanged在系统事件专用线程触发,原实现直接访问 WPF UI 对象,跨线程访问会抛InvalidOperationException并终止进程;现封送到主线程Dispatcher,并在Window_Closed取消订阅UserPreferenceChanged。HandleFloatingBarRecovery的DelayAction回调在 Timer 线程直接执行ViewboxFloatingBarMarginAnimation,现改为只负责Dispatcher.BeginInvoke封送。watchdogTimer回调整体增加try/catch,避免看门狗自身异常成为闪退源。WindowOverviewModel.WindowsUpdated、SystemEventMonitor的ForegroundWindowChanged/ProcessChanged、RulesetService的StatusUpdated等事件订阅者异常加兜底,避免在 Timer 线程上冒泡。DelayAction/TimerTrigger/ 时间与日期显示定时器回调增加异常保护。测试情况
由于无可测试环境,尚未测试。