csharp-async

Enforce asynchronous C# best practices for Task, ValueTask, and exception handling.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-async-cloudywing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-async
Source: https://github.com/CloudyWing/ai-dotfiles/tree/main/skills/csharp-async
Command: npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-async-cloudywing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enforces practical asynchronous programming conventions for C# to reduce deadlocks, blocking calls, inconsistent APIs, and incorrect exception handling across codebases.

Core Features & Use Cases

  • Naming conventions: Require Async suffix for asynchronous methods and keep names aligned with synchronous counterparts.
  • Return type guidance: Prefer Task and Task<T> as default, consider ValueTask<T> for high-frequency, low-allocation scenarios, and avoid async void except for event handlers.
  • Exception handling and cancellation: Wrap await expressions in try/catch when appropriate, propagate exceptions correctly, use Task.FromException for non-async faulted tasks, and accept CancellationToken for long-running work.
  • Concurrency and performance: Recommend Task.WhenAll for parallel independent work, Task.WhenAny for timeouts or first-completed tasks, avoid unnecessary async/await state machines by returning Task directly when possible, and prohibit blocking calls such as Result or Wait.

Quick Start

Use the csharp-async skill to refactor a C# async method to follow Async suffix naming, choose appropriate Task/ValueTask return types, add ConfigureAwait guidance, ensure proper exception propagation, and accept cancellation.

Frequently Asked Questions about csharp-async

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

FAQPage Schema
How do I avoid deadlocks and blocking calls in C# async methods?

To avoid deadlocks in C# async methods, prohibit blocking calls like .Result or .Wait(), use ConfigureAwait appropriately, and return Task directly instead of unnecessary async/await state machines.

When should I use ValueTask instead of Task in C# asynchronous programming?

Use ValueTask<T> in C# for high-frequency, low-allocation scenarios to reduce overhead, but prefer Task and Task<T> as the default return types for standard asynchronous method implementations.

What is the best way to handle exceptions and cancellation in C# Task-based code?

Handle exceptions in C# Task-based code by wrapping await expressions in try/catch, using Task.FromException for non-async faulted tasks, and accepting CancellationToken for long-running work.

How do I refactor synchronous C# code to follow async naming conventions and best practices?

Refactor C# code to async by requiring the Async suffix for asynchronous methods, aligning names with synchronous counterparts, and applying consistent Task concurrency patterns like Task.WhenAll.

Why does async void cause problems in C# libraries and services?

Async void causes problems in C# libraries because callers cannot await the operation and unhandled exceptions crash the process; avoid it except for top-level event handlers.

Can I use Task.WhenAll and Task.WhenAny for C# concurrency in performance-sensitive applications?

Use Task.WhenAll for parallel independent work and Task.WhenAny for timeouts or first-completed tasks to optimize concurrency and performance in C# applications.