csharp-concurrency-patterns
Agent skill fromAaronontheweb/dotnet-skills
Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.
How to install csharp-concurrency-patterns
install csharp-concurrency-patterns
# install the dotnet-skills pack with the skills CLI
npx skills add Aaronontheweb/dotnet-skills# or add only this skill to Claude Code: copy the folder
skills/csharp-concurrency-patterns/
# into
~/.claude/skills/csharp-concurrency-patterns/ (all projects)
.claude/skills/csharp-concurrency-patterns/ (one project)
1# .NET Concurrency: Choosing the Right Tool23## When to Use This Skill45Use this skill when:6- Deciding how to handle concurrent operations in .NET7- Evaluating whether to use async/await, Channels, Akka.NET, or other abstractions8- Tempted to use locks, semaphores, or other synchronization primitives9- Need to process streams of data with backpressure, batching, or debouncing10- Managing state across multiple concurrent entities1112## Reference Files1314- [advanced-concurrency.md](advanced-concurrency.md): Akka.NET Streams, Reactive Extensions, Akka.NET Actors (entity-per-actor, state machines, cluster sharding), and async local function patterns1516## The Philosophy1718**Start simple, escalate only when needed.**1920Most concurrency problems can be solved with `async/await`. Only reach for more sophisticated tools when you have a specific need that async/await can't address cleanly.2122**Try to avoid shared mutable state.** The best way to handle concurrency is to design it away. Immutable data, message passing, and isolated state (like actors) eliminate entire categories of bugs.2324**Locks should be the exception, not the rule.** When you can't avoid shared mutable state:251. **First choice:** Redesign to avoid it (immutability, message passing, actor isolation)262. **Second choice:** Use `System.Collections.Concurrent` (ConcurrentDictionary, etc.)273. **Third choice:** Use `Channel<T>` to serialize access through message passing28…
Excerpt shown under the repository's MIT license.
