Skip to content
Preptima
mediumCodingConceptMidSeniorStaff

You kick off background work from a controller action and it throws once the response has gone out. What is happening?

Detached ASP.NET Core background work can fail after the response because the request scope is disposed. Copy required values, create a fresh service scope, and run tracked work through IHostedService, BackgroundService or a durable queue.

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Do not fire-and-forget request-scoped work from an ASP.NET Core controller. Once the response completes, HttpContext and scoped services may be gone. Copy the data needed, enqueue the work, create a fresh scope in a hosted worker, and let the host track failures and shutdown.

Keep aspnet core explicit in the answer because that is the concept the interviewer is actually trying to test. A good aspnet core explanation names the trade-off, the failure mode, and the evidence you would use before choosing. Use aspnet core once more at the decision point so the answer reads as judgement rather than a detached example.

Keep aspnet core explicit in the answer because that is the concept the interviewer is actually trying to test. A good aspnet core explanation names the trade-off, the failure mode, and the evidence you would use before choosing.

Was this answer helpful?

Likely follow-ups

  • Where does a DbContext for work that outlives the request come from, and who disposes it?
  • The pod is drained mid-deployment. What happens to work already queued in memory, and what would you change to survive that?
  • What does async void do with an exception, and where does that exception surface?
  • How do you carry the correlation identifier into the background work once the accessor returns null?

Related questions

Further reading