What problem does it solve?
Provides clear, practical guidelines to implement and review .NET background workers so they run reliably without crashing the host, leak scoped services, or block shutdown.
Core Features & Use Cases
- Selection Guidance: When to choose BackgroundService versus IHostedService for long-running loops or one-time initialization.
- Resilience Patterns: Proper CancellationToken propagation, loop-level exception handling, OperationCanceledException filtering, and use of PeriodicTimer to avoid overlapping ticks.
- Queue-based Workers: Channel-based producer-consumer queues with scoped service resolution via IServiceScopeFactory or IDbContextFactory for safe background processing.
- Use Case: Implement an order synchronization worker, periodic metrics collector, or HTTP-request-backed background job queue that survives errors and stops cleanly.
Quick Start
Ask the skill to review a BackgroundService implementation and report missing CancellationToken propagation, direct injection of scoped services, unhandled exceptions in loops, and registration/start-stop ordering issues.