How to use IHostedService in ASP.Net Core

Take advantage of the IHostedService interface to execute background tasks in your ASP.Net Core applications

We often need to execute background tasks and scheduled jobs in our applications. To implement background tasks in ASP.Net Core, you can take advantage of Azure WebJobs or any of a number of third-party task schedulers like Quartz or Hangfire.

In ASP.Net Core, you can implement background tasks as hosted services as well. A hosted service is a class that implements the IHostedService interface and includes the necessary code for running tasks in the background. This article presents a discussion of how we can build hosted services in ASP.Net Core.

At the time of this writing, Visual Studio 2019 is available for free download. If you don’t already have a copy of Visual Studio 2019 installed in your system, you can download it from Microsoft’s Visual Studio downloads page

Create an ASP.Net Core project in Visual Studio

First off, let’s create an ASP.Net Core project in Visual Studio. To do that, follow the steps given below to create a new ASP.Net Core project in Visual Studio 2019.

To continue reading this article register now