Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides building long-running .NET background services using BackgroundService, Generic Host, graceful shutdown, and health checks.
Use this skill ↓91% 95%+5 ptsof test cases passed
Passed 21 of 22 test cases with the skill, and 20 of 22 without it.
What interface structure should be defined for an asynchronous background task queue that supports queuing work items as delegates with scoped service provider access?
Defines methods for queuing work items taking Func<IServiceProvider, CancellationToken, ValueTask>.
3 of 3 safety checks passed
This reference documents common mistakes when building .NET worker services and provides corrective guidance.
Problem: Long-running operations in StartAsync block other hosted services from starting.
// BAD: Blocks host startup
public class BadWorker : BackgroundService
{
public override async Task StartAsync(CancellationToken cancellationToken)
{
// This blocks all other hosted services from starting
await LoadLargeDatasetAsync();
await WarmupCachesAsync();
await base.StartAsync(cancellationToken);
}
}
Correction: Move initialization to ExecuteAsync:
// GOOD: Non-blocking startup
public class GoodWorker : BackgroundService
{
private bool _initialized;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
// Initialize in ExecuteAsync, not StartAsync
await LoadLargeDatasetAsync(stoppingToken);
await WarmupCachesAsync(stoppingToken);
_initialized = true;
Next to this one in the catalogue, plus more from the same author.