wasAsked.

Compare background services, queues, and scheduled jobs for long-running work in ASP.NET Core.

Flipkart · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, Messaging, ASP.NET Core

Community answers

Posted by wasAsked editorial collection

Use BackgroundService for process-local recurring or queue-consuming work, a durable broker for reliable cross-service work, and a job scheduler when you need persisted schedules, retries, dashboards, or distributed coordination. Example: protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await foreach (var job in queue.ReadAllAsync(stoppingToken)) { using var scope = scopeFactory.CreateScope(); await scope.ServiceProvider.GetRequiredService<IJobHandler>() .HandleAsync(job, stoppingToken); } } Bound queues for backpressure, create scopes per item, make handlers idempotent, persist important jobs before acknowledging, and use exponential retry plus a dead-letter path. Do not capture request services or fire-and-forget tasks. Record attempts, duration, correlation, and final outcome.

Backbencher Developer · · 0 likes

Sign in to add your answer

Related interview topics