New to Claude Skills? Learn how to install them →

github on GitHub

C# Async Best Practices

OfficialFree

Master asynchronous programming in C# with proven techniques.

by github37.7k stars on github/awesome-copilot
2 views
Updated Aug 10, 2026
Get this skill

Free · Opens the source repo

What C# Async Best Practices does

The C# Async Best Practices skill provides developers with essential guidelines for writing efficient and maintainable asynchronous code in C#. Asynchronous programming is a critical aspect of modern application development, particularly in environments where responsiveness and performance are paramount. This skill focuses on best practices that help avoid common pitfalls and improve the overall quality of async code.

The skill emphasizes proper naming conventions, such as appending 'Async' to method names, which enhances code readability and clarity. It also outlines appropriate return types for async methods, advocating for the use of Task<T> and Task while suggesting ValueTask<T> in performance-sensitive scenarios. Exception handling is another key area covered, with recommendations on using try/catch blocks effectively and avoiding the common mistake of swallowing exceptions.

Performance considerations are crucial in asynchronous programming, and this skill provides strategies like using Task.WhenAll() for parallel task execution and employing cancellation tokens for long-running operations. It also warns against practices that can lead to deadlocks or performance degradation, such as using .Wait() or mixing blocking and async code.

This skill is designed for C# developers who want to enhance their understanding of asynchronous programming and implement best practices in their projects. By following these guidelines, developers can produce cleaner, more efficient, and more reliable asynchronous code that adheres to industry standards.

When to use it

Use this skill when you need to implement or review asynchronous code in C# and want to ensure adherence to best practices.

When not to use it

This skill may not be suitable for projects that do not involve asynchronous programming or for developers already well-versed in C# async practices.

What you can build with it

Implementing an Async API

When developing an API that requires non-blocking operations, use this skill to ensure that your async methods follow best practices.

Code Review for Async Methods

During a code review, leverage this skill to identify potential issues in async implementations and suggest improvements based on established guidelines.

Optimizing Performance in Async Code

If you are facing performance issues in your async code, refer to this skill for strategies to enhance execution and resource management.

How to install C# Async Best Practices

View source

1. Install with the skills CLI

npx skills add github/awesome-copilot/csharp-async --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by github

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.

Frequently asked questions about C# Async Best Practices

Similar skills