This looks harmless:
Task.Run(() => DoWork());
❌ Why it breaks production
-
Bypasses request lifecycle
-
Ignores cancellation
-
Starves thread pool under load
✅ Correct Pattern
Use background services:
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken ct)
{
while (!ct.IsCancellationRequested)
await DoWorkAsync(ct);
}
}
