The Problem: You are firing off Task.Run() in a controller and hoping it finishes, but the server kills it.
The Fix: Implement BackgroundService. It’s the reliable, built-in way to run long-running processes.
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
// Your logic here
await Task.Delay(1000, stoppingToken);
}
}
}

