Skip to main content

Claude/ChatGPT Prompt to Find and Fix C# Async/Await Pitfalls

Audit C# code for async/await bugs -- sync-over-async, async void, missing ConfigureAwait -- with before/after fixes and a short why for each.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a senior C# engineer reviewing async code for deadlock and throughput bugs. Show working before/after diffs, not descriptions.

Context:
- Code: <paste code>
- App type: ASP.NET Core web API
- Runtime concern: thread starvation under load

Deliverables:
1. Sync-over-async: every .Result and .Wait() that risks a deadlock.
2. Library calls missing ConfigureAwait(false), and where it does not matter.
3. async void outside event handlers, and the Task-returning fix.
4. Unnecessary Task.Run in request handlers that just burns threadpool.
5. Captured HttpContext or scoped services in background tasks.
6. For each: before code, after code, and a one-line explanation of the failure mode.

Output: a numbered list, each item a before/after pair plus the why.

What this prompt does

This prompt makes the model a senior C# engineer reviewing async code for deadlock and throughput bugs, returning working before/after diffs rather than descriptions. You paste your [code], set the [app_type], and name a [runtime_concern], and it hunts for sync-over-async, missing ConfigureAwait, async void misuse, unnecessary Task.Run, and captured scoped services in background tasks — fixing each with a before/after pair and a one-line explanation of the failure mode.

The structure works because async bugs are nearly invisible in a code read but lethal under concurrency, so the prompt insists on paste-ready fixed code instead of a lecture. The classic culprit — a .Result or .Wait() deep in a service causing thread-pool starvation — gets surfaced first. [runtime_concern] (for example, thread starvation under load) tells the model which failure mode to prioritise, and [app_type] decides whether ConfigureAwait advice even applies, since it matters in library code but not in ASP.NET Core request handlers. Pairing each fix with a one-line explanation of the failure mode is what makes the review teachable: the team learns why the change matters, so the same mistake is less likely to reappear in the next pull request.

When to use it

  • An app stalls or deadlocks under load and you suspect sync-over-async.
  • You're seeing thread-pool starvation and want every .Result and .Wait() flagged.
  • You want async void outside event handlers found and converted to Task-returning.
  • You suspect unnecessary Task.Run in request handlers burning threadpool.
  • You're worried about captured HttpContext or scoped services in background tasks.
  • You want paste-ready fixes your team can apply, not a write-up to re-read.

Example output

Expect a numbered list where each item is a before/after pair: the offending code, the corrected version, and a one-line explanation of the failure mode it fixes. Items cover sync-over-async, ConfigureAwait gaps, async void, needless Task.Run, and captured scoped services. The diffs are concrete enough to apply directly rather than paraphrased advice.

Pro tips

  • Paste real [code] into the prompt — the more actual code you give it, the more grounded the diffs.
  • Set [runtime_concern] to your real symptom so the model prioritises the matching failure mode.
  • Use [app_type] accurately; ConfigureAwait(false) advice is relevant in libraries but largely moot in ASP.NET Core endpoints.
  • Reproduce the deadlock under concurrency first, then confirm the suggested fix actually clears it — a fix that compiles isn't proof.
  • Watch for the async void cases; outside event handlers they swallow exceptions and are easy to miss.
  • Apply one category of fix at a time so you can attribute any behaviour change to the right change.
  • Check the background-task findings carefully; a captured HttpContext or scoped service can throw only intermittently, which makes it brutal to diagnose later.
  • Don't blindly sprinkle Task.Run to "make things async" — the prompt flags exactly the cases where it just burns threadpool for no gain.

Frequently Asked Questions

Does it show fixed code or just explain the problems?
It returns before/after pairs for each issue plus a one-line explanation of the failure mode, so your team can paste the corrected code directly. The prompt explicitly asks for working diffs rather than prose descriptions.
Will it flag ConfigureAwait everywhere, even where it doesn't matter?
No. It distinguishes library calls that genuinely need ConfigureAwait(false) from places it does not matter, such as ASP.NET Core request handlers. Setting `[app_type]` accurately helps it apply that distinction correctly to your code.
What's the main async bug it looks for first?
Sync-over-async — every `.Result` and `.Wait()` that risks a deadlock or thread-pool starvation. This is the most common cause of apps stalling under load, so it leads the review, especially when `[runtime_concern]` names thread starvation.
Can it review code without me reproducing the bug?
It can review pasted `[code]` statically and suggest fixes, but you should still reproduce the deadlock under concurrency and confirm the fix clears it. A change that compiles is not proof the failure mode is actually resolved.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in C# & .NET Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support