csharp-concurrency-patterns

Guides selection of .NET concurrency abstractions from async/await to Channels and Akka.NET actors.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-concurrency-patterns-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-concurrency-patterns
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/csharp-concurrency-patterns
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-concurrency-patterns-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing the wrong concurrency primitive in .NET leads to deadlocks, race conditions, and over-engineered code. This Skill provides a decision framework for picking the right abstraction—async/await, Parallel.ForEachAsync, Channels, Reactive Extensions, Akka.NET Streams, or Akka.NET Actors—based on the actual problem. ## Core Features & Use Cases - Decision Tree Guidance: Maps common scenarios (I/O waits, CPU-bound parallelism, producer/consumer queues, state machines) to the appropriate .NET concurrency tool. - Anti-Pattern Detection: Identifies and corrects locks for business logic, manual thread management, blocking on async code, and unprotected shared mutable state. - Advanced Patterns Reference: Covers Akka.NET Streams for backpressure and batching, Reactive Extensions for UI event composition, and entity-per-actor patterns with Cluster Sharding. - Use Case: When building a background order-processing service, use this Skill to decide between a bounded Channel for simple queuing versus Akka.NET actors for stateful per-order lifecycle management. ## Quick Start Ask the AI which .NET concurrency approach fits your scenario, such as processing a work queue with backpressure or managing state for thousands of entities.

Frequently Asked Questions about csharp-concurrency-patterns

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

FAQPage Schema
How do I choose between async/await, Channels, and Akka.NET in C#?

Use async/await for I/O-bound operations, Channel<T> for producer/consumer work queues, and Akka.NET actors for stateful entity management or state machines. Start with async/await and escalate only when you have a concrete need it cannot address.

What .NET tool should I use for producer/consumer patterns?

System.Threading.Channels is the recommended tool for producer/consumer patterns and work queues in .NET. Bounded channels provide backpressure, and the async reader/writer API decouples producers from consumers without manual locking.

Reactive Extensions vs Akka.NET Streams: which should I use?

Use Reactive Extensions for UI event composition like debouncing search input or combining event sources. Use Akka.NET Streams for server-side pipelines needing backpressure, batching, throttling, or distributed processing.

When should I use Akka.NET actors instead of async/await?

Use Akka.NET actors when managing thousands of entities with independent state, implementing state machines with Become(), needing supervision and restart semantics, or distributing work across nodes with Cluster Sharding. Simple request/response flows should stay with async/await.

Why is locking considered an anti-pattern in .NET concurrency?

Locks protect shared mutable state, which is the root cause of most concurrency bugs. Prefer redesigning with immutability or message passing first, then ConcurrentDictionary, then Channels to serialize access, using lock only as a last resort for short critical sections.

What happens if I block on async code with .Result or .Wait()?

Blocking on async code with .Result or .Wait() risks deadlocks, especially in contexts with a synchronization context like UI apps. The correct approach is async all the way: await the task and propagate CancellationToken through the call chain.