# dotnet-csharp-async-patterns

dotnet-csharp-async-patterns teaches AI agents proper C# async patterns, stopping common blunders like .Result deadlocks, unhandled fire-and-forget tasks, and dropped cancellation tokens.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 136 installs · ★ 92 repo stars
- Author: wshaddix
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/dotnet-csharp-async-patterns/SKILL.md
- Updated: 2026-02-27
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/dotnet-csharp-async-patterns

## What it does

Language models frequently introduce subtle concurrency bugs into .NET code. They block on tasks synchronously, drop incoming cancellation tokens, or spawn unmonitored `async void` methods that can crash an entire process. This skill supplies concrete instructions to enforce the standard async pipeline across every layer.

The rules define when to prefer `ValueTask` over standard tasks during high-throughput synchronous completions and how to apply `IAsyncEnumerable` for memory-efficient streaming. It also details parallel operations using `Parallel.ForEachAsync` from modern .NET runtime versions.

Using `.GetAwaiter().GetResult()` or `.Result` in ASP.NET Core controllers will exhaust the thread pool under load. Because of this, the guide strictly redirects background jobs into `BackgroundService` or managed worker channels.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/dotnet-csharp-async-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/dotnet-csharp-async-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/dotnet-csharp-async-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/dotnet-csharp-async-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install wshaddix/dotnet-skills skills/dotnet-csharp-async-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/dotnet-csharp-async-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/wshaddix/dotnet-skills --path skills/dotnet-csharp-async-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/dotnet-csharp-async-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-async-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/wshaddix/dotnet-skills/tree/HEAD/skills/dotnet-csharp-async-patterns/SKILL.md

## When to use it
- Eliminate deadlocks caused by `.Result` and synchronous task waiting
- Pass `CancellationToken` instances across asynchronous call chains
- Stream batch query responses with `IAsyncEnumerable`
- Prevent unobserved exceptions originating from `async void` routines

## Example prompts
- Refactor this repository method to accept and propagate a `CancellationToken`
- Convert this cache lookup routine to return a `ValueTask`
- Set up parallel processing for this list using `Parallel.ForEachAsync`

## Similar
- [dotnet-patterns](https://affpapa.org/en/nevibecode/skills/dotnet-patterns.md) — skill · 6300 installs
- [csharp-async](https://affpapa.org/en/nevibecode/skills/csharp-async.md) — skill · 10883 installs
- [csharp-concurrency-patterns](https://affpapa.org/en/nevibecode/skills/csharp-concurrency-patterns.md) — skill · 1600 installs
- [openapi-to-application-csharp-dotnet](https://affpapa.org/en/nevibecode/plugins/openapi-to-application-csharp-dotnet.md) — plugin · ★ 41430 repo stars
- [dotnet-backend-patterns](https://affpapa.org/en/nevibecode/skills/dotnet-backend-patterns.md) — skill · 19076 installs
- [async-python-patterns](https://affpapa.org/en/nevibecode/skills/async-python-patterns.md) — skill · 18055 installs

From the same set: [wshaddix/dotnet-skills](https://affpapa.org/en/nevibecode/by/wshaddix/dotnet-skills.md) — 24 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
