ASP. NET Mvc5+ef6+easyui Background Management system (-quartz) A detailed description of job scheduling usage

Source: Internet
Author: User

Objective

I started using it from Quartz2.0 and encapsulated the interface, which can be referred to http://www.cnblogs.com/ymnets/p/5065154.html

Recently took out to optimize, and upgrade to the latest version, warm so know new

At the beginning of the tutorial is less, and is English, now many places have a Chinese language tutorial is also learning to do more.

What can quartz achieve?

He resembles a SQL Server Agent with a timer timer:

1. Specify a time to execute an SQL statement or stored procedure

2. Send a message at a specified time (execute a C # method)

3. Regularly perform what you want to do (by configuring Cron expressions), such as: 1,3,5 send a text message to the user every week

4. Job tasks He can be suspended, suspended, stopped

5. Job tasks can be remotely managed by operations, database storage (supporting a variety of databases including: Sqlserver,sqlite,oracle,mysql,firebird)

How to use

Install directly from the NuGet package

A simple implementation

We create a new console program and install the Quartz package

Entry Code:

usingQuartz;usingQuartz.impl;usingSystem;namespacequartztest{classProgram {Static voidMain (string[] args) {            //First We must get a reference to a schedulerIschedulerfactory SF =Newstdschedulerfactory (); IScheduler sched=SF.            Getscheduler (); Ijobdetail Job= jobbuilder.create()              . Withidentity ("Job1","Group21")              .            Build (); //when do I start?DateTime RunTime =DateTime.Now; Itrigger Trigger=triggerbuilder.create (). Withidentity ("Trigger1","group1")            . StartAt (RunTime). Withsimpleschedule (x=x. Withintervalinseconds (1)//1 seconds, a real man .. RepeatForever ())//Infinite Loops            .            Build (); Sched.            Schedulejob (Job, trigger); //Start a taskSched.                   Start (); }    }}
usingQuartz;usingSystem;usingSystem.Threading.Tasks;namespacequartztest{/// <summary>    ///This was just a simple job, that says, "Hello" to the world. /// </summary>    /// <author>Bill Kratzer</author>    /// <author>Marko Lahma (. NET)</author>     Public classHellojob:ijob {/// <summary>         ///called by the<see cref= "IScheduler"/>When a/// <see cref= "Itrigger"/>fires that's associated with/// the<see cref= "IJob"/>. /// </summary>         Public  voidExecute (Ijobexecutioncontext context) {Console.WriteLine ("Hello Quartz"); //Say Hello to the world and display the Date/time        }    }}

Operation Result:

You can also run in the form of an expression:

            Itrigger trigger2 = triggerbuilder.create ()                                       . Withidentity ("trigger2""group1")                                       . StartAt (RunTime)                                       . Withcronschedule ("/1 * *?") * *")    // time     expression, 1 seconds                                        . Build ();            Sched. Schedulejob (Job, trigger2);

The effect is the same!

Let's take a look at a class diagram:

This class diagram describes the fundamentals of quartz operation.

How to learn its expression

We don't have to memorize the meaning of his expression. http://cron.qqe2.com/interface Display Configuration

You can see the build expression through the operation of the interface, and use it a few times to understand.

Background package into the interface, more need not to remember the expression, through the interface configuration can

Of course, you need to know the meaning of characters, such as: *,? and other symbols, with a bit similar to the wildcard, you can Baidu

Note: In fact, the function we are going to do is based on this interface, and then hand-selected the generated expression as a running timer.

Summarize

Quartz is much more useful than a timer timer to deploy a Windows task

1.HELLOJOB integrates the Ijob interface shown in the class diagram and implements the void Execute (Ijobexecutioncontext context) method, which is required!

2. by Stdschedulerfactory.getdefaultscheduler (); To get a scheduler

3. Add the task to the trigger

4. Start the task and run automatically

Official Links:

Quartz.net Official 2.X Tutorial http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/index.html

Quartz.net Source Code Https://github.com/quartznet/quartznet

Article Code:

Link: Http://pan.baidu.com/s/1pKP6c2Z Password: Dudi

ASP.-quartz Job scheduling usage (Mvc5+ef6+easyui)

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.