.NET: reports that do not hold the application hostage

Exporting thousands of records should not interrupt daily work. Design background jobs with visible progress and recoverable failures.

Download a report — then wait indefinitely

Imagine an administration panel generating a monthly export inside one HTTP request. The connection times out, the user clicks again, and the server starts another copy. Nobody knows whether the first operation is still running.

ASP.NET Core provides hosted services and BackgroundService for background processing. Microsoft's documentation explains their lifecycle. Moving code into such a service does not, by itself, make a job survive a process failure.

Separate acceptance from execution

An example design records the request and returns a job identifier. The user sees a state: waiting, processing, ready or failed. A worker prepares the file, which can be downloaded later.

Decide whether another click creates a new report or returns the existing job. Also define the data's reference point: should the report reflect the moment it was requested or the moment it runs? This affects interpretation more than the progress animation does.

Design for interruption

Persist job state when losing work is unacceptable. Limit concurrent exports and define retries. Test a worker stopping halfway through generation and storage running out of space.

The finished report still needs access control when downloaded. Define its availability period and cleanup process. Measure queue waiting time, execution time and failures separately. The team can then distinguish slow generation from a backlog of jobs waiting for a worker.