Asp.net Long-Running-Background-Task. Best Practice?

Viewed 767

I have an Asp.net Core WebApp and a lot of Reports inside an MongoDB. Now I want to build a Service which gets a large Bunch of this Reports (with all dependecies and a lot of Screenshot), generates PDFs and put them in Zip and store them in the GridFS.

This would be a lot of work. But what is the best way to do it?

Something of these: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-6.0&tabs=visual-studio#consuming-a-scoped-service-in-a-background-task

Or should I only use a Service with a single async Task ?

1 Answers

Microsoft says IHostedService. From Background tasks with hosted services in ASP.NET Core:

In ASP.NET Core, background tasks can be implemented as hosted services. A hosted service is a class with background task logic that implements the IHostedService interface. This article provides three hosted service examples:

Related