Hangfire Getting Started (Task Scheduler)

Source: Internet
Author: User
Tags connection reset

First, Introduction

British Civil Service Network: http://hangfire.io/

Open Source Address: Https://github.com/HangfireIO

Hangfire is not dependent on the specific. NET application types, including. NET and. NET Core.

The Hangfire is a powerful one. NET open source Background task tool without Windows Service/Task Scheduler.

Can be used with an ASP. NET application or it can be used in the console. Hangfire can create new, different kinds of tasks with just a few simple lines of code.

Ii. Conditions of Use

1. The. NET Framework 4.5

2. Persistent storage (SQL Azure, SQL Server version R2 and above, Redis )

3. Newtonsoft.json version ≥5.0.1

III. Installation and use

1. Create a console project, use the NuGet command-line installation, select the corresponding project

2. pm> install-package Hangfire, installation will be a while, patient waiting

3. After the installation, it can be used in the main method.

classProgram {Static voidMain (string[] args) {globalconfiguration.configuration. Usecolouredconsolelogprovider (). Usesqlserverstorage ("server=.; User Id=sa; password=123456;database=xxxx; Connection Reset=false;"); //supports queue-based task processing: task execution is not synchronous, but is placed in a persistent queue to return the request control immediately to the caller. //Backgroundjob.enqueue (() = Console.WriteLine ("simple!")); //deferred task execution: Instead of calling the method immediately, set a future point in time to execute. //Backgroundjob.schedule (() = Console.WriteLine ("reliable!"), Timespan.fromseconds (5)); //Recurring task execution: a line of code that adds a recurring task that has a common time-loop pattern built in, or a cron expression that can be used to set complex patterns. //recurringjob.addorupdate (() = Console.WriteLine ("transparent!"), cron.minutely);//Note The minimum unit is the minute                         using(varServer =NewBackgroundjobserver ()) {Backgroundjob.enqueue ()= Console.WriteLine ("Simple111")); Console.WriteLine ("Hangfire Server started. Press any key to exit ...");            Console.readkey (); }        }    }

Reference article:

Http://www.cnblogs.com/redmoon/p/4394962.html

Http://www.cnblogs.com/huangchenqin/p/5210448.html

http://codeopinion.com/background-tasks/

Hangfire Getting Started (Task Scheduler)

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.