async-patterns

Detect async anti-patterns and enforce CancellationToken propagation in .NET code.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill async-patterns-faysilalshareef
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: async-patterns
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/core/async-patterns
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill async-patterns-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Async-patterns helps eliminate common asynchronous programming bugs in .NET such as unpropagated cancellation, deadlocks caused by blocking on async code, unobserved exceptions from fire-and-forget usage, and inefficient async patterns that harm performance.

Core Features & Use Cases

  • Propagates guidance to accept and forward CancellationToken through call chains to enable cooperative cancellation.
  • Recommends and explains patterns for parallelism, streaming, hot-path optimization with ValueTask, async initialization, and timeout handling with linked CancellationTokenSources.
  • Detects anti-patterns including async void, blocking on Task with Result or GetAwaiter, inappropriate Task.Run usage in request handlers, and misused ConfigureAwait.
  • Use cases include auditing web endpoints for cancellation support, converting blocking calls to await-based flows, implementing producer/consumer channels, and designing robust BackgroundService scoped work.

Quick Start

Use the async-patterns skill to audit your .NET project for missing CancellationToken propagation and blocking async calls.

Frequently Asked Questions about async-patterns

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

FAQPage Schema
How do I properly propagate CancellationToken through async call chains in .NET?▼

To propagate CancellationToken correctly, accept and forward the token through every method in your async call chain to enable cooperative cancellation. This prevents unpropagated cancellation bugs and ensures long-running operations can be safely aborted.

Why does blocking on async code with .Result cause deadlocks and how do I fix it?▼

Blocking on async code with .Result or GetAwaiter causes deadlocks by tying up the synchronization context. Replace synchronous waits with await-based flows to prevent deadlocks and ensure efficient asynchronous execution in .NET applications.

When should I use ValueTask instead of Task for async hot-path optimization?▼

Use ValueTask instead of Task for async hot-path optimization when operations often complete synchronously. ValueTask reduces allocations in high-throughput scenarios, improving performance while maintaining reliable async/await patterns in .NET.

What is the best way to implement timeouts for async operations using CancellationTokenSource?▼

Implement timeouts by creating linked CancellationTokenSources that combine a timeout token with an existing cancellation token. This pattern allows you to enforce time limits on async operations while preserving cooperative cancellation from callers.

How do I design a robust BackgroundService with proper async scoping in .NET?▼

Design robust BackgroundService scoping by using async/await patterns, propagating CancellationToken, and avoiding async void methods. This ensures reliable background processing, proper exception handling, and cooperative shutdown in hosted services.

What async anti-patterns should I avoid when writing concurrent .NET code?▼

Avoid async void methods, blocking on Task with .Result, inappropriate Task.Run usage in request handlers, and misused ConfigureAwait. These async anti-patterns cause unobserved exceptions, deadlocks, and performance degradation in .NET applications.