Back to Skills

csharp-async-patterns

verified

Use when C# async/await patterns including Task, ValueTask, async streams, and cancellation. Use when writing asynchronous C# code.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-csharp

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-csharp/skills/csharp-async-patterns/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-csharp/skills/csharp-async-patterns/SKILL.md -a claude-code --skill csharp-async-patterns

Installation paths:

Claude
.claude/skills/csharp-async-patterns/
Powered by add-skill CLI

Instructions

# C# Async Patterns

Master asynchronous programming in C# using async/await, Task, ValueTask, async
streams, and cancellation patterns. This skill covers modern asynchronous patterns
from C# 8-12 for building responsive, scalable applications.

## Async/Await Fundamentals

The async/await pattern provides a simple way to write asynchronous code that
looks and behaves like synchronous code.

### Basic Async Method

```csharp
public async Task<string> FetchDataAsync(string url)
{
    using var client = new HttpClient();
    string result = await client.GetStringAsync(url);
    return result;
}

// Calling the async method
public async Task ProcessAsync()
{
    string data = await FetchDataAsync("https://api.example.com/data");
    Console.WriteLine(data);
}
```

### Async Method Signature Rules

```csharp
// ✅ Correct - Returns Task
public async Task ProcessDataAsync()
{
    await Task.Delay(1000);
}

// ✅ Correct - Returns Task<T>
public async Task<int> CalculateAsync()
{
    await Task.Delay(1000);
    return 42;
}

// ⚠️ Only for event handlers - Returns void
public async void Button_Click(object sender, EventArgs e)
{
    await ProcessDataAsync();
}

// ❌ Wrong - Not async but returns Task
public Task WrongAsync()
{
    // Should be async or use Task.FromResult
    return Task.CompletedTask;
}
```

## Task and Task&lt;T&gt;

Task represents an asynchronous operation. Task&lt;T&gt; represents an operation
that returns a value.

### Creating Tasks

```csharp
// Task.Run for CPU-bound work
public async Task<int> CalculateSumAsync(int[] numbers)
{
    return await Task.Run(() => numbers.Sum());
}

// Task.FromResult for already-computed values
public Task<string> GetCachedValueAsync(string key)
{
    if (_cache.TryGetValue(key, out var value))
    {
        return Task.FromResult(value);
    }
    return FetchFromDatabaseAsync(key);
}

// Task.CompletedTask for void async methods
public Task ProcessIfNeededAsync(bool condition)
{
    if (!condition)
    {
        ret

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
19831 chars