Designs and diagnoses .NET asynchronous and concurrent work, including cancellation, task ownership, synchronization, channels, and race conditions. Use for correctness or throughput under concurrency; do not use for runtime dump/counter investigations alone (use dotnet-diagnostics).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Async Concurrency?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/k4ndev-async-concurrency)
---
name: async-concurrency
description: Designs and diagnoses .NET asynchronous and concurrent work, including cancellation, task ownership, synchronization, channels, and race conditions. Use for correctness or throughput under concurrency; do not use for runtime dump/counter investigations alone (use dotnet-diagnostics).
---
# Async and Concurrency
## Purpose
Ensure asynchronous work is cancellable, observed, bounded, and safe across its full lifecycle.
## Scope
`Task`, async/await, cancellation, locks, shared state, channels, parallelism, hosted work, and `DbContext` concurrency.
## When to use
- A race, deadlock, starvation, lost update, stuck task, or cancellation bug is described.
- User asks to design background processing or bounded asynchronous work.
## Do not use for
- Collecting runtime traces/dumps/counters without code-level design: use `dotnet-diagnostics`.
- Broker delivery guarantees/outbox design: use `messaging-patterns`.
- EF query tracking/migration behavior: use `efcore-patterns`.
## Required context
Trace task creation/await chain, token source and owner, exception observation, shared mutable state, scheduler/host lifetime, queue limits, and whether side effects have committed.
## Workflow
1. Build a lifecycle graph: creator, owner, cancellation trigger, completion observation, and resource disposal.
2. Find sync-over-async (`.Result`, `.Wait()`, `GetAwaiter().GetResult()`), `async void` (except deliberate event handlers), and unobserved fire-and-forget.
3. Identify synchronization and shared mutable state; never await while holding `lock`; protect invariants, not arbitrary code duration.
4. Propagate `CancellationToken` through cancellable calls. Separate request cancellation from durable post-commit work with explicit ownership/queueing.
5. Bound parallelism, channels, retry loops, and in-flight memory; define overload/backpressure behavior.
6. Do not concurrently use a single EF `DbContext`; create separate units of work if parallelism is required.
7. Test cancellation, concurrent access, queue saturation, exceptions, and shutdown deterministically; use gates/fakes rather than sleeps.
## Decision rules
- Fire-and-forget is acceptable only with a supervising owner that records failures and stops with the host.
- Use `Channel<T>` for producer/consumer work when bounded capacity and backpressure are needed; choose full-mode behavior deliberately.
- `ConfigureAwait(false)` depends on application context and project rules; do not apply blindly to UI code.
## Expected output format
Show task ownership and cancellation path, relevant race/deadlock interleaving, corrected approach, overload/shutdown behavior, and deterministic test cases.
## Common mistakes
- Creating detached tasks, using one context concurrently, unbounded `Task.WhenAll`, swallowing cancellation, or passing request-aborted tokens after a durable commit without a policy.
## Edge cases
- Cancellation is cooperative and does not roll back completed side effects.
- Disposing a `CancellationTokenSource` while consumers still register/use it can race; lifetime must cover all consumers.
- Locks may be correct for short synchronous invariants; async primitives are not automatically faster or safer.
## Examples
See [async examples](examples.md) for bounded channel consumption and unsafe detached work.
## Test scenarios
- Positive: “A request starts 100 tasks and shares one DbContext; fix cancellation and concurrency safely.”
- Negative: “Review a protobuf field-number change” routes to `api-contract-review` / `dotnet-code-review`.
- Boundary: a production hang asks both code-flow analysis here and dump/trace collection via `dotnet-diagnostics`.
## Related skills
`dotnet-diagnostics`, `messaging-patterns`, `efcore-patterns`, `testing-quality`, `logging-observability`.