csharp-concurrency-patterns

Select .NET concurrency abstractions for async/await, Channels, Akka.NET workflows.

3|Updated Jan 24, 2024
One-click install
npx skills add https://github.com/akoken/dotfiles --skill csharp-concurrency-patterns-akoken
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-concurrency-patterns
Source: https://github.com/akoken/dotfiles/tree/main/config/.copilot/skills/csharp-concurrency-patterns
Command: npx skills add https://github.com/akoken/dotfiles --skill csharp-concurrency-patterns-akoken

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill guides .NET developers to select the most appropriate concurrency abstraction for a given scenario, helping to avoid unnecessary locks and manual synchronization by choosing async/await, Channels, Akka.NET, Reactive Extensions, or other patterns based on the context.

Core Features & Use Cases

  • Guidance on when to apply async/await for I/O-bound tasks and asynchronous workflows.
  • Recommendations for using System.Threading.Channels to implement producer/consumer queues with backpressure.
  • Scenarios for leveraging Akka.NET Actors and state machines to manage many independent entities.
  • UI and client-side event streams with Reactive Extensions (Rx) for responsive experiences.
  • Practical approach: systematically evaluate requirements and select a pattern before refactoring to improve maintainability and scalability.

Quick Start

  1. Identify the dominant concurrency need in your project (I/O, CPU-bound, streaming, or stateful coordination).
  2. Choose the recommended pattern (async/await, Channels, Akka.NET, or Rx) and wire up a minimal example.
  3. Replace global locks with the chosen abstraction and measure correctness and throughput.

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 the right concurrency pattern for .NET applications?

Choosing the right .NET concurrency pattern requires evaluating your dominant need: use async/await for I/O-bound tasks, Channels for producer/consumer queues, Akka.NET for stateful entities, and Rx for UI event streams.

When should I use System.Threading.Channels over async/await in .NET?

Use System.Threading.Channels instead of async/await when implementing producer/consumer queues that require backpressure. Async/await is better suited for general I/O-bound workflows and asynchronous task coordination.

What is the best way to manage stateful entities in .NET without using locks?

To manage stateful entities without locks, leverage Akka.NET Actors and state machines. This concurrency abstraction handles many independent entities safely by avoiding shared mutable state and manual synchronization.

Does Reactive Extensions (Rx) work for client-side UI event streams in .NET?

Reactive Extensions (Rx) works effectively for .NET client-side UI event streams. It provides responsive experiences by managing asynchronous data streams and events without requiring manual synchronization.

How to refactor .NET code to remove global locks and shared mutable state?

Refactor .NET code by systematically evaluating requirements, selecting an appropriate concurrency abstraction like Channels or Akka.NET, wiring up a minimal example, replacing global locks, and measuring correctness and throughput.

Why does my producer/consumer queue need backpressure handling in .NET?

Producer/consumer queues need backpressure handling to prevent fast producers from overwhelming slow consumers. System.Threading.Channels provides this built-in coordination, avoiding unbounded memory growth and manual locking.