Catalog
github/csharp-async

github

csharp-async

Get best practices for C# async programming

v1.0Latest
New~455Updated Jun 26, 2026

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

Files1
1 files · 1.0 KB

Select a file to preview

Overall Score

76/100

Grade

B

Good

Safety

95

Quality

72

Clarity

82

Completeness

65

Summary

This skill provides structured guidance on C# async programming best practices, covering naming conventions, return types, exception handling, performance optimization, and common pitfalls. It serves as a reference guide for code reviewers and developers to identify and suggest improvements to asynchronous code patterns.

Detected Capabilities

code analysispattern recognitiondocumentation reading

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

review async codec# async patternstask-based designasync antipatternsawaiting best practices

Use Cases

  • Review C# async/await code for best practice compliance
  • Identify async antipatterns like async void or blocking calls
  • Guide migration from blocking to task-based asynchronous patterns
  • Optimize async method naming and return type selection
  • Implement cancellation tokens and timeout patterns in async code

Quality Notes

  • Skill provides practical, well-organized async best practices with clear sections covering naming, return types, exception handling, performance, pitfalls, and patterns
  • Actionable guidance with concrete examples (e.g., 'ConfigureAwait(false)' for library code, 'ValueTask<T>' for high-performance scenarios)
  • Content is accurate and reflects established C# async patterns from Microsoft and community consensus
  • No file writes, shell execution, or environment access — purely advisory and analytical in nature
  • Could be strengthened by including code examples showing correct vs. incorrect patterns
  • No discussion of async initialization patterns (async constructors via factory methods) or async disposal patterns (IAsyncDisposable)
  • Lacks guidance on testing async code or debugging async issues
Model: claude-haiku-4-5-20251001Analyzed: Jun 26, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use github/csharp-async in your dev environment

Command Palette

Search for a command to run...

github/csharp-async | SkillRepo