This article is mainly for you to introduce in detail the use of the. NET quartz.net, with a certain reference value, interested in small partners can refer to
Quartz.net is the job scheduling framework, the specific content is as follows
1. Add quartz.net references to the project (use NuGet management here)
Create a new class Timingjob, which is primarily used to implement task logic
Using quartz;using system;namespace quartznetdemo{//<summary>///Scheduled Task class///</summary> public class Timingj ob:ijob {public void execute (ijobexecutioncontext context) { //The logical code to be executed periodically is written here Console.WriteLine ("Task executed");}}
In Program.cs: (Here is the console application)
Using quartz;using quartz.impl;using System;namespace quartznetdemo{class Program {static void Main (string[] args) {
ischedulerfactory SF = new Stdschedulerfactory (); IScheduler Scheduler = SF. Getscheduler (); Ijobdetail job = jobbuilder.create<timingjob> (). Withidentity ("Job1", "MyGroup"). Build (); Itrigger trigger = Triggerbuilder.create (). StartAt (DateTime.Now.AddSeconds (5)). Withcronschedule ("/2 * *?") * *"). Build (); Scheduler. Schedulejob (Job,trigger); Scheduler. Start (); } }}
When the program runs, after 5 seconds, each interval 2 seconds output information
Cron expression:
Quartz. The cron expression in net uses the form "/5 * *?" * * * "Such a 7-bit expression, the last year is not required, the expression from left to right, according to this is the second, minute, time, month days, months, weeks, years
Special characters and explanations:
, or the meaning.
/A/b. A: Represents the start time, B frequency time. The
* frequency. That is, every fluctuation.
-Interval.
? Any value. That is, every fluctuation. Can only be used in DayOfMonth and DayOfWeek, both conflict. Specify a different one to use? The
L represents the last. Can only be used on DayOfMonth and DayOfWeek
W days. Represents the last. Can only be used in DayOfWeek
#x #y. Only use DayOfMonth. The first Y week of the month X