PluginBench
Skill
Official
Review
Audit score 70

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-async
Claude Code
Cursor
Windsurf
Cline

How to use csharp-async

  1. 1.Install the skill using the provided npm command
  2. 2.Share your C# code for review or ask for async pattern guidance
  3. 3.The skill will identify naming, return type, exception handling, and performance issues
  4. 4.Apply suggested improvements following the best practices guidelines
  5. 5.Use the patterns for new async method implementations

Use cases

Good for
  • 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
Who it's for
  • 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

When should I use ValueTask<T> instead of Task<T>?

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.

Why should I avoid async void methods?

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.

What does ConfigureAwait(false) do?

ConfigureAwait(false) prevents the continuation from running on the captured synchronization context, reducing deadlock risk in library code and improving performance.

Is it safe to use .Wait() or .Result on a Task?

No. Using .Wait() or .Result in async code can cause deadlocks. Always use await instead to properly handle asynchronous execution.

When should I use Task.WhenAll() vs Task.WhenAny()?

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() 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.