Running Reliable Background Tasks with IHostedService in .NET Core
Replace ad-hoc threads with IHostedService and BackgroundService to run reliable background tasks that respect shutdown, handle scoped dependencies, and avoid crashing your .NET Core application.