Scheduler in .Net Core 2.1 Hangfire tutorial

Background:

I used to setup my project scheduler by using windows service, mostly sending emails, then I find a better library to do this task — Hangfire. There are multiple reasons, the first is Hangfire is free!!! and then it provide dashboard to monitor and control your scheduled tasks, the last point is it is easy to setup.

Options:

Before we get into this Hangfire tutorial make sure you compare all the libraries otherwise you need to refactor your application which is waste of time. After compare these options and ask a friend, I decided to use Hangfire to handle the scheduling emails.

You can search them in NuGet Package Manager. The version number does not matter.

Because I use .Net Core 2.1 so that I install Hangfire.AspNetCore rather than Hangfire please make sure you select the right one for your project. The Hangfire.Dashboard.Authorization is to implement the security feature which means it is optional and the SqlServer is a must-have.

Step 2: Startup Configuration

After the installation let’s go to the Startup.cs file then you need to do the following things.

Under the

public void ConfigureServices(IServiceCollection services)

Add the following code. These codes is to configure the Hangfire can access your database.