General
98 installs
C# Async Programming Best Practices
by github/awesome-copilot
Get best practices for C# async programming
Skill content
Best practices guide for C# asynchronous programming patterns and pitfalls. - Covers naming conventions (Async suffix), return types (Task, ValueTask, avoid void), and exception handling strategies including ConfigureAwait and Task.FromException - Highlights performance optimization techniques: Task.WhenAll for parallel execution, Task.WhenAny for timeouts, and cancellation token usage - Documents critical pitfalls to avoid: blocking calls like .Wait() and .Result, async void methods outside event handlers, and mixing blocking with async code - Recommends implementation patterns including async command pattern, async streams (IAsyncEnumerable), and task-based asynchronous pattern (TAP) for public APIs C# Async Programming Best Practices Your goal is to help me follow best practices for asynchronous programming in C#. Naming Conventions - Use the 'Async' suffix for all async methods - Match method names with their synchronous counterparts when applicable (e.g., GetDataAsync() for GetData()) Return Types - Return Task<T> when the method returns a value - Return Task when the method doesn't return a value - Consider ValueTask<T> for high-performance scenarios to reduce allocations - Avoid returning void for async methods except for event handlers Exception Handling