Use when C# async/await patterns including Task, ValueTask, async streams, and cancellation. Use when writing asynchronous C# code.
View on GitHubTheBushidoCollective/han
jutsu-csharp
January 24, 2026
Select agents to install to:
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-patternsInstallation paths:
.claude/skills/csharp-async-patterns/# 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<T>
Task represents an asynchronous operation. Task<T> 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