csharp-async

Review C# async code and apply Task, ValueTask, and ConfigureAwait best practices.

1|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/leonanpereirapinto/ai-utils --skill csharp-async-leonanpereirapinto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-async
Source: https://github.com/leonanpereirapinto/ai-utils/tree/main/skills/dotnet/csharp-async
Command: npx skills add https://github.com/leonanpereirapinto/ai-utils --skill csharp-async-leonanpereirapinto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Async programming in C# is error-prone and can cause deadlocks, cluttered code, and performance issues. This skill provides a structured set of best practices to write safer, faster, and more maintainable asynchronous code.

Core Features & Use Cases

  • Naming conventions: suffix Async to asynchronous methods and align names with their synchronous counterparts where possible.
  • Return types and task composition: prefer Task/Task<T> and consider ValueTask in high-frequency scenarios; avoid void async except for event handlers; use Task.WhenAll/Task.WhenAny for parallelism and timeouts.
  • Exception handling and resilience: wrap awaits with try/catch where appropriate; use ConfigureAwait(false) in library code; propagate errors with Task.FromException when building Task-returning methods.
  • Performance and safety: minimize unnecessary awaits, avoid mixing sync and async, use cancellation tokens for long operations; avoid blocking calls like .Wait() or .Result.
  • Pitfalls and patterns: implement the TAP pattern, consider IAsyncEnumerable for streaming, and prefer asynchronous abstractions in public APIs.

Quick Start

Review a C# codebase to apply async best practices and refactor methods accordingly.

Frequently Asked Questions about csharp-async

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent deadlocks in C# async code?

To prevent deadlocks in C# async code, avoid blocking calls like .Wait() and .Result, use ConfigureAwait(false) in library code, and prefer async/await throughout the call chain.

What is the best way to handle exceptions in asynchronous methods?

The best way to handle exceptions in asynchronous methods is wrapping awaits with try/catch blocks and propagating errors using Task.FromException when building Task-returning methods without using async.

When should I use ValueTask instead of Task in C#?

Use ValueTask instead of Task in C# high-frequency scenarios where an asynchronous operation often completes synchronously, minimizing unnecessary heap allocations and improving performance.

Can I use async void in event handlers?

Yes, you can use async void in event handlers, as it is the only appropriate scenario for this pattern; avoid async void for all other application code to prevent unhandled exceptions.

How do I run multiple asynchronous tasks in parallel?

Run multiple asynchronous tasks in parallel by using Task.WhenAll for concurrent execution and Task.WhenAny to implement timeouts or process the first completing task efficiently.