Hangfire is a powerful tool for performing background tasks. For details, please refer to the introduction on the official website: https://www.hangfire.io/
Create a new one asp.net Core MVC project
Introducing nuget package Hangfire.AspNetCore
The task of hangfire requires database persistence. We modify configureservices in the startup class
Then enable the hangfire Middleware in the configure method
Now when we run the project, we can see that many tables are automatically generated in the database. These tables are used to persist tasks
We can open the following address to see the job control panel of hangfire. There are no jobs open now
Add a periodic job to the configure method to execute the output every minute
Start the application again
The output job already exists.
Modify the code again. Suppose there are two tasks to send and receive messages. Then write an interface IMessage, which implements the interface
Register in starup,
Then use it in the configure method
start the program again
There are two new jobs.
The above is just hangfire’s asp.net Simple use in core.
This article is about hangfire ASP.NET The simple implementation method in core is all the content shared by Xiaobian. I hope I can give you a reference, and I hope you can support developeppaer more.