Csharp Async
GitHubOfficialOriginally contributed by @aaronpowell as prompts/csharp-async.prompt.md; moved into a skill by pull request #761Distributed by GitHub
- Skill
- Guidelines
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured set of guidelines for C# developers to write efficient, safe, and maintainable asynchronous code. It covers essential topics including naming conventions, proper return types, robust exception handling, and performance optimization techniques. By adhering to these standards, developers can avoid common pitfalls like deadlocks and blocking calls, ensuring their applications leverage the Task-based Asynchronous Pattern (TAP) effectively.
What it does
- Provides naming conventions for asynchronous methods.
- Outlines correct return types for async operations.
- Defines strategies for handling exceptions in async code.
- Offers performance tips for task execution and resource management.
- Identifies common anti-patterns to avoid in C# development.
- Suggests implementation patterns for long-running operations and data streams.
When to use it
- When you need to review existing C# code for async-related issues.
- When designing new asynchronous APIs or services in C#.
- When troubleshooting performance bottlenecks or deadlocks in async code.
- When establishing coding standards for a development team.
Advantages
- Helps prevent common async pitfalls like deadlocks.
- Promotes consistent code structure across projects.
- Improves application performance through better task management.
- Ensures robust error handling in asynchronous workflows.
Usage examples
- “Review my code for async best practices.”
- The agent analyzes your C# code, checking for issues like blocking calls, incorrect return types, or missing ConfigureAwait(false) usage, and provides specific refactoring suggestions.
- “Should I use Task or ValueTask in this method?”
- The agent explains the performance trade-offs between Task and ValueTask, helping you decide based on your specific allocation and performance requirements.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/github/csharp-async/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip csharp-async.zip -d .agents/skills
Documentation by aaronpowell
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 valueReturn
Taskwhen the method doesn't return a valueConsider
ValueTask<T>for high-performance scenarios to reduce allocationsAvoid 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 codePropagate exceptions with
Task.FromException()instead of throwing in async Task returning methods
Performance
Use
Task.WhenAll()for parallel execution of multiple tasksUse
Task.WhenAny()for implementing timeouts or taking the first completed taskAvoid 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 codeAvoid 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.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.1 KiB
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md1.8 KiB
Requirements and compatibility
Written for: GitHub Copilot
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Originally contributed by
@aaronpowellas prompts/csharp-async.prompt.mdmoved into a skill by pull request #761
- Publisher
- GitHub (Official)
- Distributed by
- GitHub
- Source
- github/awesome-copilot · skills/csharp-async · commit 797337f
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Contributors
- aaronpowell, CypherHK, derekclair, jamesmontemagno
AutoGineer is not affiliated with or endorsed by aaronpowell or GitHub.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download csharp-async.zip