csharp-async
github/awesome-copilot
Best practices guide for C# async/await programming patterns and performance optimization.
What is csharp-async?
This skill provides guidance on C# asynchronous programming best practices, including naming conventions, return types, exception handling, and performance optimization. Use it when writing or reviewing async C# code to ensure proper patterns and avoid common pitfalls.
- Enforce async method naming conventions with 'Async' suffix
- Recommend appropriate return types (Task<T>, Task, ValueTask<T>) based on method behavior
- Guide exception handling in async contexts with try/catch and ConfigureAwait usage
- Identify performance anti-patterns like .Wait() and .Result blocking calls
- Suggest parallel execution patterns using Task.WhenAll() and Task.WhenAny()
- Recommend async streams and task-based asynchronous patterns for APIs
How to install csharp-async
npx skills add https://github.com/github/awesome-copilot --skill csharp-asyncHow to use csharp-async
- 1.Install the skill using the provided npm command
- 2.Share your C# code for review or ask for async pattern guidance
- 3.The skill will identify naming, return type, exception handling, and performance issues
- 4.Apply suggested improvements following the best practices guidelines
- 5.Use the patterns for new async method implementations
Use cases
- Reviewing C# code for async/await compliance and best practices
- Designing async APIs with proper naming and return type conventions
- Optimizing performance-critical async operations with ValueTask and cancellation tokens
- Refactoring blocking code to use proper async patterns
- Implementing long-running operations with async command patterns
- C# developers writing asynchronous code
- Backend engineers building async APIs
- Library authors designing public async interfaces
- Code reviewers checking async implementation quality
csharp-async FAQ
Use ValueTask<T> in high-performance scenarios where you want to reduce allocations, particularly when the method frequently completes synchronously. For most library code, Task<T> is preferred.
Async void methods cannot be awaited and make exception handling difficult. Use them only for event handlers. Return Task or Task<T> for all other async methods.
ConfigureAwait(false) prevents the continuation from running on the captured synchronization context, reducing deadlock risk in library code and improving performance.
No. Using .Wait() or .Result in async code can cause deadlocks. Always use await instead to properly handle asynchronous execution.
Use Task.WhenAll() to wait for all tasks to complete in parallel. Use Task.WhenAny() to get the first completed task, useful for implementing timeouts or racing operations.
Full instructions (SKILL.md)
Source of truth, from github/awesome-copilot.
name: csharp-async description: 'Get best practices for C# async programming'
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()forGetData())
Return Types
- Return
Task<T>when the method returns a value - Return
Taskwhen the method doesn't return a value - Consider
ValueTask<T>for high-performance scenarios to reduce allocations - Avoid returning
voidfor async methods except for event handlers
Exception Handling
- Use try/catch blocks around await expressions
- Avoid swallowing exceptions in async methods
- Use
ConfigureAwait(false)when appropriate to prevent deadlocks in library code - Propagate exceptions with
Task.FromException()instead of throwing in async Task returning methods
Performance
- Use
Task.WhenAll()for parallel execution of multiple tasks - Use
Task.WhenAny()for implementing timeouts or taking the first completed task - Avoid unnecessary async/await when simply passing through task results
- Consider cancellation tokens for long-running operations
Common Pitfalls
- Never use
.Wait(),.Result, or.GetAwaiter().GetResult()in async code - Avoid mixing blocking and async code
- Don't create async void methods (except for event handlers)
- Always await Task-returning methods
Implementation Patterns
- Implement the async command pattern for long-running operations
- Use async streams (IAsyncEnumerable<T>) for processing sequences asynchronously
- Consider the task-based asynchronous pattern (TAP) for public APIs
When reviewing my C# code, identify these issues and suggest improvements that follow these best practices.
Related skills
More from github/awesome-copilot and the wider catalog.
git-commit
Execute semantic git commits with conventional message analysis and intelligent staging.
excalidraw-diagram-generator
Generate Excalidraw diagrams from natural language descriptions.
documentation-writer
Create structured technical documentation using the Diátaxis framework for tutorials, how-to guides, references, and explanations.
gh-cli
GitHub CLI comprehensive reference for repositories, issues, PRs, Actions, projects, releases, and all GitHub operations from the command line.
prd
Generate comprehensive Product Requirements Documents with executive summaries, user stories, technical specs, and risk analysis.
refactor
Surgical code refactoring to improve maintainability without changing behavior.