Fire-and-forget tasks die with requests.
Daily micro-tips for C#, SQL, performance, and scalable backend engineering.
Fire-and-forget tasks die with requests.
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken ct)
{
while (!ct.IsCancellationRequested)
await DoWorkAsync(ct);
}
}
Why this matters
Hosted services respect app lifetime and graceful shutdown.