Using Hangfire to Execute Background Processing in ASP.Net by@cisin

Using Hangfire to Execute Background Processing in ASP.Net

Amit Agarwal HackerNoon profile picture

Amit Agarwal

Founder and COO at Cyber Infrastructure which is a software development company.

What's Hangfire?

Hangfire includes an additional layer to your code. When you use Hangfire, it stores the layer into its own data set. Hangfire then, at that point deals with the calls for you, so you don't need to stress over the job you've listed and it will be done smoothly. On the off chance that it falls flat, it even retries it naturally in the manner in which you would do it. Hangfire additionally gives you a pleasant neat dashboard using which you can take a look at your listed tasks and, in the event that you so wish, oversee them manually. It really is a great little structure. Hangfire permits you to simultaneously list a task in your code, and deploys the code non-concurrently through the early bird gets the worm line.

You can connect with a reliable Microsoft web app development to get the process done.

A couple of instances of the kinds of jobs:

  • Fire-and-forget
  • Delayed
  • Recurring
  • Continuations of other jobs

The tasks you've listed will be saved inside tenacious storage fitting your very own preference. They support numerous well-known stores, social or record based. The advantage is that, in any event, during irregular closures, your tasks are protected and fit to be dealt with when the application has restarted.

Imagine a scenario where something turned out badly and my job tosses an exemption. Nothing to stress over truly. Hangfire has its own programmed retry tool that retries your tasks for you in an insightful way. Hangfire utilizes laborers to deal with the errands, you decide the number of laborers you need and they share the line, running the undertakings on an ‘early bird gets the worm’ premise. Hangfire's UI is itself ensured by an API key and available from/hangfire in the event that you have the API key.

Planning and checking background is a testing job. Each enormous application needs to carry out background checks to complete background jobs, for example, data handling, email updates, and preparing SMS lines and email lines. Windows Service is the most regular way to deal with the need.

Today, we are going to Hangfire and keep in touch with some code to plan an underlying position in the ASP .NET Core project.

Hangfire is a known open-source library that developers use to design and deploy background jobs in ASP.NET apps. You'll have the option to make a basic background measure within a similar application pool or string without making separate applications. The library makes background jobs in persistent storage, similar to MongoDB, or MS SQL Server, that might keep you from losing employment on reusing exception prevalence or IIS pools.

ASP.NET Core is presently a typical platform for Web API and MVC with no different project creation need.

Once the task is ready, introduce Hangfire from NuGet. You can introduce Hangfire either from NuGet Package Manager, or you can choose a Package Management Console, depending upon your preferences and budget, and time in hand.

How can it function?

Hangfire handles various kinds of background jobs, and every one of them is conjured in a different execution setting.

With Hangfire, you can do the following:

Fire and forget

These jobs are executed on a quick basis only once after formation. When you make a fire-and-forget job, you can save it to its line ("default" of course, however various lines are upheld). The line is paid attention to by several committed labourers that bring some job and perform it.


After the given delay, the job will be placed in its line and conjured as a standard fire-and-forget job.


Repeating jobs will repeat on each characterized interval. You can characterize spans from milliseconds to years.

Continuations Continuations permit you to characterize complex job processes by tying numerous background jobs together.

Change the Dashboard URL

As a matter of course, Hangfire is set on “http://<website-url>/hangfire” to get to the dashboard. It's not difficult to design your custom URL.

Access Remotely

Default Hangfire design sets up for native environment as it were. To make a Hangfire job on creation ambiance, we need to carry out a custom IAuthorizationFilter. Microsoft Technology Associate will help you understand this process better.


Signup or Login to Join the Discussion


Related Stories