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.