csharp-async-patterns

Enforce correct async/await usage and error handling in C# code.

1|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/afonsoft/VideoChat --skill csharp-async-patterns-afonsoft
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-async-patterns
Source: https://github.com/afonsoft/VideoChat/tree/main/.agents/skills/csharp-async-patterns
Command: npx skills add https://github.com/afonsoft/VideoChat --skill csharp-async-patterns-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers write correct, efficient asynchronous code in C#, avoiding common pitfalls.

Core Features & Use Cases

  • Basic Async/Await: Consistent use of async/await with proper error handling and avoiding async void.
  • Advanced Patterns: IAsyncEnumerable, ValueTask, and async factory usage for scalable, high-performance services.
  • Reliability & Performance: Cancellation tokens, ConfigureAwait usage, retry policies, and asynchronous streams to maximize throughput.

Quick Start

Refactor a representative blocking method into an asynchronous version using proper async/await, cancellation support, and error handling.

Frequently Asked Questions about csharp-async-patterns

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

FAQPage Schema
How do I avoid async void in C# and handle errors correctly?

To avoid async void in C#, use async Task for event handlers and apply proper error handling with try-catch blocks. This ensures exceptions propagate correctly and prevents application crashes from unobserved asynchronous failures.

What is the best way to use ConfigureAwait and CancellationToken in C# async methods?

The best way to use ConfigureAwait and CancellationToken in C# is to pass tokens through method parameters and apply ConfigureAwait(false) in library code. This maximizes throughput and allows cooperative cancellation of async operations.

When should I use ValueTask instead of Task for high-performance C# services?

You should use ValueTask instead of Task in C# when an asynchronous operation frequently completes synchronously. This reduces heap allocations and optimizes performance in high-throughput data layers and scalable services.

How do I use IAsyncEnumerable for asynchronous streams in C#?

To use IAsyncEnumerable for asynchronous streams in C#, return IAsyncEnumerable<T> from your method and iterate with await foreach. This enables efficient, real-time asynchronous data streaming without buffering entire collections.

Why does my C# async code block the thread and reduce responsiveness?

Your C# async code blocks the thread when using synchronous calls like .Result or .Wait() instead of await. Refactoring blocking methods into proper async/await patterns restores responsiveness and prevents deadlocks.

Can I use async factory patterns for scalable C# applications?

Yes, you can use async factory patterns in C# by creating static async methods that initialize objects asynchronously. This pattern is essential for scalable services requiring asynchronous data loading during construction.