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)