Summary
You can now start to do some more complex things with an IHostedService
and the BackgroundService
. Be careful with background services because they all run in the same application; if you use too much CPU or memory, this could slow down your application.
For bigger applications, I would suggest running such tasks in a separate application that is specialized for executing background tasks: a separate Docker container, a BackgroundWorker
on Azure, Azure Functions, or something like that. However, it should be separate from the main application in that case.
In the next chapter, we will learn about middleware, and how you can use them to implement special logic on the request pipeline or serve specific logic on different paths.