Skill Press

No. 323 · csharp-async

C# Async Programming Best Practices

A field guide from GitHub Awesome Copilot contributors

GitHub Awesome Copilot contributors

When to use it

Get best practices for C# async programming

Rank
No. 323 of 971
Installs
Not listed yet
Built for
GitHub Copilot
Runs in
GitHub Copilot
Length
251 words · 1 min
Files
2
License
MIT

Get this skill

Download the skill folder (.zip, 2 KB) ↓ · SKILL.md only ↓

Agent prompt

Paste into a coding agent with terminal access. Check the upstream requirements for the skill you’re installing.

Prompt
Install the "csharp-async" Agent Skill by GitHub Awesome Copilot contributors, from https://github.com/github/awesome-copilot.

1. Fetch the whole folder skills/csharp-async — SKILL.md plus every script, reference, and asset beside it, not just SKILL.md. For example:
   skill_checkout=$(mktemp -d)
   git init "$skill_checkout"
   git -C "$skill_checkout" fetch --depth 1 https://github.com/github/awesome-copilot.git 1683f50e94c9fd489191f73d7c8f7e2bd871bd0c
   git -C "$skill_checkout" checkout --detach FETCH_HEAD
2. Copy it into your skills directory as a folder named "csharp-async":
   - Claude Code: ~/.claude/skills/csharp-async/ (all projects) or .claude/skills/csharp-async/ (this project only)
   - Another agent: the directory you load Agent Skills from (folders containing a SKILL.md)
3. Check that csharp-async/SKILL.md exists and its frontmatter says name: csharp-async.
4. Read SKILL.md, then tell me in two or three sentences what the skill does and when it will trigger, and list any dependencies it mentions (Python packages, npm packages, CLIs) that aren't installed yet. Don't install them without asking.

skills CLI

One command; the skills.sh installer detects your agents (Claude Code, Cursor, Codex, and more).

Terminal
npx skills add https://github.com/github/awesome-copilot/tree/1683f50e94c9fd489191f73d7c8f7e2bd871bd0c/skills/csharp-async --skill csharp-async

Contents

  1. Naming Conventions
  2. Return Types
  3. Exception Handling
  4. Performance
  5. Common Pitfalls
  6. Implementation Patterns

The skill, in full

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.

More in Software & Web Development

All Software & Web Development skills →

More from GitHub Awesome Copilot contributors

From github/awesome-copilot at 1683f50, MIT. Install counts from skills.sh.