csharp-async

Identify and fix asynchronous programming anti-patterns in C# code.

9|1|Updated Jul 21, 2025
One-click install
npx skills add https://github.com/usepowershell/PoshMcp --skill csharp-async-usepowershell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-async
Source: https://github.com/usepowershell/PoshMcp/tree/main/.squad/templates/skills/csharp-async
Command: npx skills add https://github.com/usepowershell/PoshMcp --skill csharp-async-usepowershell

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers identify and correct common asynchronous programming mistakes in C#, reducing deadlocks, performance regressions, and incorrect exception handling that arise from improper use of async/await, Task, and related patterns.

Core Features & Use Cases

  • Naming and API design: Encourage Async suffixes and consistent sync/async method pairs for public APIs.
  • Return type guidance: Recommend Task, Task<T>, and ValueTask<T> where appropriate and avoid async void except for event handlers.
  • Exception and cancellation handling: Advise proper try/catch around awaits, propagation of exceptions, use of ConfigureAwait(false) in library code, and CancellationToken usage.
  • Performance and patterns: Promote Task.WhenAll/WhenAny for parallelism, avoid blocking calls like .Result or .Wait, and use IAsyncEnumerable for streaming sequences.

Quick Start

Review the provided C# code for async anti-patterns and suggest concrete, safe changes that implement these best practices.

Frequently Asked Questions about csharp-async

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix C# async anti-patterns like calling .Result or .Wait?

To fix C# async anti-patterns, remove blocking calls like .Result or .Wait and replace them with await. This Skill reviews C# code to identify these deadlocks and suggests safe, non-blocking Task-based patterns.

When should I use ValueTask instead of Task in C# async code?

You should use ValueTask instead of Task in C# async code when a method often completes synchronously, reducing heap allocations. This Skill provides return type guidance to correctly apply Task, Task<T>, and ValueTask<T> in performance-sensitive services.

Why does async void cause exceptions to crash my C# application?

Async void causes unhandled exceptions because the calling method cannot await them, leading to application crashes. This Skill identifies async void usage and recommends avoiding it except for top-level event handlers to ensure correct exception propagation.

What is the best way to handle CancellationToken in C# async methods?

The best way to handle CancellationToken in C# async methods is to pass it through method signatures and check it during long-running operations. This Skill advises on proper cancellation support and exception handling patterns for async/await.

How do I use IAsyncEnumerable for streaming data in C#?

To use IAsyncEnumerable for streaming sequences in C#, yield return items asynchronously within an async method. This Skill promotes IAsyncEnumerable to replace buffered collections and improve performance in async streaming scenarios.

Does my C# library need ConfigureAwait(false) for async calls?

Yes, your C# library needs ConfigureAwait(false) to prevent capturing the synchronization context and avoid deadlocks. This Skill enforces ConfigureAwait usage in library code to ensure safer and faster asynchronous execution.