Generated banner for Csharp Async
Generated logo for Csharp Async

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

From the author

Get best practices for C# async programming
— the description by aaronpowell

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

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/github/csharp-async/download
  2. Unzip 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() 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

  • 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.

Files

SKILL.md

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

  • 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.

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
GitHub avatar of aaronpowell@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