同步 I/O、async void 和静态事件订阅需要整理 [AI Review]

Open
#3,818 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp

Research direction

Start with the listed call sites in Requester.cs, Request.cs, ProjectQuery.cs, LoaderBase.cs, and the UI files named in the issue. Trace how their callers handle cancellation, UI dispatch, and page lifetimes before changing the synchronous waits or static event subscriptions. Done means meeting all four acceptance checks across the affected network, dialog, loader, and event code; the issue does not identify tests.

Written by the indexing model from the issue text.

Description

⭕ 等待处理

🤖 这条 Issue 由 AI 代码审计批量生成,未经人工逐项复核。基线:dev@2856c2a4(迁移范围 9c4f1544..2856c2a4)。证据来自静态代码分析,欢迎在评论中补充或纠正。

现象

网络和文件操作里还有不少同步等待。事件处理器里有 async void,静态事件订阅也缺少释放。

证据

  • PCL.Launcher.Core/Network/Http/Requester.cs:37,53,58,68:内部使用 GetAwaiter().GetResult()。
  • PCL.Launcher.Core/Comp/Request.cs:28,56,86、Comp/ProjectQuery.cs:565,577:用 Task.Run 包同步网络请求。
  • PCL.Launcher/UI/UiInteraction.cs:64,83,102,121、ExitFlow.cs:80、StartupEffects.cs:237,263、FileDragHandler.cs:137,291,379,540:对话框使用 .Result。
  • PCL.Launcher.Core/Loading/LoaderBase.cs:255-259,294-301:用 Thread.Sleep(10) 轮询,已经存在的 WaitForExitAsync 没有被调用。
  • PCL.Launcher/Views/Pages/Instance/PageInstanceScreenshot.cs:41:公开的 async void Refresh() 没有 try/catch。
  • PCL.Launcher/ViewModels/Pages/PageToolsGameLinkViewModel.cs:73-83:订阅 9 个静态事件,Suspend() 只取消公告 CTS,没有解除订阅。
  • PCL.Launcher/Views/Pages/Launch/PageLaunchLeft.axaml.cs:63-64,81、PageLaunchRight.axaml.cs:79、PageSetupLeft.axaml.cs:65、MainWindow.axaml.cs:57:静态事件订阅没有对应的解除。

影响

线程池线程会被同步 I/O 占住,取消操作可能失效。页面或 ViewModel 被静态事件保留,重启或测试时无法释放。async void 抛出的异常会进入全局未处理路径。

建议

  • 把 Requester 改成异步接口,调用方逐步改为 await。
  • 对话框统一使用 ShowAsync,去掉 .Result。
  • 把 LoaderBase 的异步等待方法接到实际调用点,删除轮询。
  • 事件边界保留 async void 时补 try/catch,公开方法改成 async Task。
  • 页面和 ViewModel 实现 IDisposable 或 OnNavigatedFrom 解绑,静态事件成对出现。

验收

  • 网络和文件操作不再用 Task.Run 包同步调用。
  • 对话框调用不再阻塞 UI 线程。
  • 页面离开后静态事件不再持有旧实例。
  • async void 都有异常处理。
Dominant language
C#
Stars
4.3k
Forks
148
Avg merge
1d 6h
Merged PRs (30d)
64

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PCL-Community/PCL-CE

All issues in PCL-Community/PCL-CE

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.