dotnet-csharp-async-patterns

Guide async/await usage in C# with cancellation and task patterns.

71|10|Updated Feb 11, 2026
One-click install
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns-wshaddix
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-csharp-async-patterns
Source: https://github.com/wshaddix/dotnet-skills/tree/main/skills/dotnet-csharp-async-patterns
Command: npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns-wshaddix

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write correct, efficient, and robust asynchronous code in C#, avoiding common pitfalls that lead to deadlocks, thread starvation, and unhandled exceptions.

Core Features & Use Cases

  • Correct async/await Usage: Ensures methods are consistently async and awaited, preventing deadlocks.
  • Cancellation Handling: Implements proper CancellationToken propagation and usage for graceful termination.
  • Resource Management: Demonstrates best practices for ValueTask and streaming with IAsyncEnumerable<T>.
  • Use Case: Refactor a legacy synchronous data access layer to use async/await correctly, improving application responsiveness and scalability.

Quick Start

Use the dotnet-csharp-async-patterns skill to refactor the provided GetData method to use async/await correctly.

Frequently Asked Questions about dotnet-csharp-async-patterns

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

FAQPage Schema
How do I prevent deadlocks when using async await in C#?

To prevent deadlocks in C# async await, ensure methods are consistently marked async and properly awaited. This skill guides you to avoid blocking on asynchronous code, which causes thread starvation and deadlocks.

Why does async void cause unhandled exceptions in C#?

Async void causes unhandled exceptions in C# because callers cannot await the operation. This skill helps you refactor to correct async await patterns, ensuring robust exception handling and preventing application crashes.

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

The best way to handle CancellationToken in C# asynchronous methods is proper propagation for graceful termination. This skill demonstrates correct cancellation token usage to ensure your async operations stop cleanly when requested.

When should I use ConfigureAwait in C# async programming?

You should use ConfigureAwait in C# async programming to optimize context capturing and improve performance. This skill provides guidance on ConfigureAwait best practices within efficient asynchronous code patterns.

How do I refactor a synchronous data access layer to use async await correctly?

To refactor a synchronous data access layer to use async await correctly, apply consistent async methods and proper task patterns. This skill improves application responsiveness and scalability through correct asynchronous refactoring.

Can I use ValueTask and IAsyncEnumerable for async streaming in C#?

Yes, you can use ValueTask and IAsyncEnumerable for async streaming in C# to manage resources efficiently. This skill demonstrates best practices for these features within robust asynchronous code implementations.