csharp-concurrency-patterns

Guide .NET concurrency abstraction selection with decision trees and code examples.

Updated Dec 4, 2022
One-click install
npx skills add https://github.com/devingoble/CloudOStat --skill csharp-concurrency-patterns-devingoble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-concurrency-patterns
Source: https://github.com/devingoble/CloudOStat/tree/main/.github/skills/csharp-concurrency-patterns
Command: npx skills add https://github.com/devingoble/CloudOStat --skill csharp-concurrency-patterns-devingoble

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers choose the most appropriate concurrency abstraction in .NET, guiding them away from common pitfalls like manual locking and towards efficient, scalable solutions.

Core Features & Use Cases

  • Guidance on Abstraction Choice: Provides a decision tree for selecting between async/await, Parallel.ForEachAsync, System.Threading.Channels, Reactive Extensions, and Akka.NET.
  • Best Practices & Anti-Patterns: Illustrates correct usage and highlights common mistakes to avoid.
  • Use Case: When building a high-throughput web service, you need to process incoming requests concurrently. This Skill helps you decide whether to use async/await for I/O, Channels for a work queue, or Akka.NET actors for managing per-request state efficiently.

Quick Start

Use the csharp-concurrency-patterns skill to understand when to use async/await versus Channels for producer-consumer scenarios.

Frequently Asked Questions about csharp-concurrency-patterns

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

FAQPage Schema
What is the best concurrency abstraction in .NET for high-throughput producer-consumer work queues?

For high-throughput producer-consumer queues, System.Threading.Channels provides the optimal .NET concurrency abstraction, avoiding manual locking anti-patterns. This guidance offers decision trees to select between Channels, async/await, and reactive extensions.

How do I choose between async/await and Parallel.ForEachAsync for CPU-bound versus I/O-bound tasks?

Use async/await for I/O-bound operations and Parallel.ForEachAsync for CPU-bound parallel processing in .NET. This skill provides decision trees to map your workload to the correct concurrency pattern and avoid blocking code.

When should I use Akka.NET actors for stateful entity management instead of manual locking?

Use Akka.NET actors for stateful entity management when you need to isolate state and handle concurrent requests without manual locking. This approach prevents blocking anti-patterns by encapsulating state within message-driven actors.

Why does blocking in async code cause performance issues in .NET web services?

Blocking in async .NET code causes performance issues by exhausting thread pool threads, leading to thread starvation and reduced throughput. This skill identifies manual locking and blocking anti-patterns to help you avoid these scalability bottlenecks.

Can I use Reactive Extensions with async/await for managing concurrent data streams?

Yes, you can use Reactive Extensions with async/await in .NET to manage concurrent data streams. This skill provides decision trees for selecting between Reactive Extensions, Channels, and other abstractions for your specific streaming workloads.