How to use quartz.net in. NET Code Drawing tutorial

Source: Internet
Author: User
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

Related Article

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.