From wpf-dev-pack
Provides .NET patterns for parallel processing CPU-bound tasks using Parallel.For, PLINQ, and ConcurrentCollections to leverage multi-core processors.
npx claudepluginhub christian289/dotnet-with-claudecode --plugin wpf-dev-packThis skill uses the workspace's default tool permissions.
A guide for APIs and patterns for parallel processing of CPU-bound tasks.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
A guide for APIs and patterns for parallel processing of CPU-bound tasks.
Quick Reference: See QUICKREF.md for essential patterns at a glance.
| API | Purpose |
|---|---|
Parallel.For, Parallel.ForEach | CPU-bound parallel processing |
PLINQ (.AsParallel()) | LINQ query parallelization |
Partitioner<T> | Large data partitioning |
ConcurrentDictionary<K,V> | Thread-safe dictionary |
public sealed class ImageProcessor
{
public void ProcessImages(IEnumerable<string> imagePaths)
{
var options = new ParallelOptions
{
MaxDegreeOfParallelism = Environment.ProcessorCount
};
Parallel.ForEach(imagePaths, options, path =>
{
ProcessImage(path);
});
}
}
Parallel.For(0, data.Length, (i, state) =>
{
if (data[i] == target)
{
state.Break();
}
});
var results = data
.AsParallel()
.WithDegreeOfParallelism(Environment.ProcessorCount)
.Where(d => d.IsValid)
.Select(d => Transform(d))
.ToList();
// When order preservation is needed
var results = data
.AsParallel()
.AsOrdered()
.Select(d => Process(d))
.ToList();
| Collection | Purpose |
|---|---|
ConcurrentDictionary<K,V> | Thread-safe dictionary |
ConcurrentQueue<T> | Thread-safe FIFO queue |
ConcurrentBag<T> | Thread-safe unordered collection |
// Collecting results during parallel processing
var results = new ConcurrentBag<Result>();
Parallel.ForEach(data, item =>
{
var result = Process(item);
results.Add(result);
});
Prevents contention with thread-local variables
private readonly ThreadLocal<StringBuilder> _localBuilder =
new(() => new StringBuilder());
public void ProcessInParallel()
{
Parallel.For(0, 1000, i =>
{
var sb = _localBuilder.Value!;
sb.Clear();
sb.Append(i);
});
}
// ❌ Using Parallel for I/O operations
Parallel.ForEach(urls, url => httpClient.GetAsync(url).Result);
// ✅ Using async-await for I/O operations
await Task.WhenAll(urls.Select(url => httpClient.GetAsync(url)));
// ❌ Parallel writes to regular collection
var list = new List<int>();
Parallel.For(0, 1000, i => list.Add(i)); // Race condition!
// ✅ Using thread-safe collection
var bag = new ConcurrentBag<int>();
Parallel.For(0, 1000, i => bag.Add(i));