Dotnetcore Timer service Hangfire

Source: Internet
Author: User
Tags dotnet

# Dotnetcore Timer service Hangfire recently wrote an ASP. NET Core project, which is useful to timed tasks, and is ready to use quartz.net. After all, both in Java and in the. NET Framework are outstanding. But after looking at Quartz.net's document about ASP. NET core, I decided to switch to a timed task frame, so I chose Hangfire. Development tools: Visual Studio Code Environment:. NET core MVC 2.0① Create an ASP. Open an empty folder in VS code, and then use CTRL +, (or click on the view at the top of the terminal) to open the terminal input: dotnet New Mvc② install Hangfire in Terminal input: dotnet Add package Hangfire③ Open startup file, import dependencies: Using Hangfire; NOTE: This timing framework requires a database, if you use MSSQL Do not separate the package of the database, otherwise need to be added separately, such as dotnet add packages Hangfire.pro.redis;④ Add Database engine in Configureservices "" Publicvoidconfigureservices (iservicecollection services) {services. Addhangfire (R =>r.usesqlserverstorage (@" Server= (LocalDB) \mssqllocaldb; Database=hangfire;            trusted\_connection=true;")); Services.        Addmvc (); } ' ⑤ then add the app by adding a scheduled task at configure start the service launch framework. Usehangfireserver (); app. Usehangfiredashboard (); Recurringjob.addorupdate ();p ublicvoidconfigure (Iapplicationbuilder app, ihostingenvironment env) {if (E Nv.   Isdevelopment ())         {app.            Usedeveloperexceptionpage (); } else {app.            Useexceptionhandler ("/Home/Error"); } app.            Usehangfireserver (); App.            Usehangfiredashboard ();            Timed Tasks Recurringjob.addorupdate (() =>newcommon.weather (), cron.daily); App.            Usestaticfiles (); App.            USEMVC (Routes => {routes. MapRoute (name: "default", Template: "{ Controller=home}/{action=index}/{id?}            ");        }); Note: Common is a tool class for me, weather is the method that I need to execute on a timed basis; The cron.daily table is executed once a day, and there are many ways to execute a scheduled task, such as adding, delaying, repeating, and so on. Cron expressions are also available in a variety of ways: [HTTP/ Docs.hangfire.io/en/latest/quick-start.html] (http://docs.hangfire.io/en/latest/quick-start.html) cron expression: [HTTPS ://en.wikipedia.org/wiki/cron#cron\_expression] (https://en.wikipedia.org/wiki/Cron#CRON_expression) if using vs Code words do not execute dotnet Res before commissioningTore or dotnet Build 

Dotnetcore Timer service Hangfire

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.