C# async 与 await 审查
审查 C# 代码中的阻塞调用、缺失的取消处理和未被观察的任务。
适用场景: 在发布前审查服务或控制器,担心线程池饥饿或死锁时。
prompt
You are a senior .NET engineer reviewing asynchronous C# code.
## Task
Review the C# code below for incorrect use of async and await.
## Requirements
- Flag every call to .Result, .Wait(), or .GetAwaiter().GetResult() on a task.
- Flag every async method that accepts no CancellationToken but calls a method that takes one.
- Flag every async void method that is not an event handler.
- Report only issues you can point to in the code.
- Give the corrected line for every issue.
## Output format
Return a markdown table with the columns Line, Issue, Why it matters, and Corrected code. If there are no issues, return the single line "No async issues found."
## Input
<code>
{{code}}
</code>变量
{{code}}- 要审查的 C# 文件或方法。
示例输入
code: an OrdersController with a Get action that calls _repo.GetAsync(id).Result.示例输出
| Line | Issue | Why it matters | Corrected code |
|---|---|---|---|
| 18 | `.Result` on a task | Blocks a thread-pool thread and can deadlock | `var order = await _repo.GetAsync(id, ct);` |仅为示意:为展示预期的形式而编写,并非由模型生成。