QUARTZ. NET is a scheduled task framework and the quartz.net task framework.

Source: Internet
Author: User

QUARTZ. NET is a scheduled task framework and the quartz.net task framework.

<1>

Quartz. NET-1.0.3 file (this is an old version and now has a new version. The usage seems different)

First, add the Common. Logging. dll file and the Quartz. dll file under the bin/1.0.3/Release/Quartz/directory under the Quartz. NET-3.5 file and then add references. Introduce connected files into the project

Using Quartz; using Quartz. impl; using System. collections. generic; using System. linq; using System. threading. tasks; using System. windows. forms; namespace test scheduled task {static class Program {/// <summary> /// main entry point of the application. /// </Summary> [STAThread] static void Main () {/* QUARTZ. NET is a concept of a scheduled task framework: planner: ischedjob; Work IJob; Trigger: Trigger; we first get an isched and then create a job (IJob ), throw the task to the planner and tell it under what conditions (Trigger) the code of the task to be scheduled to be executed can be written to the Execute method of the IJob interface, when the time comes, the Execute method will be called. CrondTrigger is a trigger set through the Crond expression, and simple triggers such as SimpleTrigger. You can use the MakeDailyTrigger of TriggerUtils to Execute the trigger once a day ), makeHourlyTrigger (executed every hour) and other methods to simplify calling. */IScheduler sched; ISchedulerFactory sf = new StdSchedulerFactory (); sched = sf. getScheduler (); // This Is A planner JobDetail job = new JobDetail ("job1", "group1", typeof (TestJob); // TestJob is a class that implements the IJob interface, we need to define it ourselves, so we will add a TestJob class under the project. And let it implement the Ijob interface. DateTime ts = TriggerUtils. getNextGivenSecondDate (null, 5); // the first running starts after 5 seconds // TimeSpan interval = TimeSpan. fromHours (1); // execute once every 1 hour // TimeSpan interval = TimeSpan. fromSeconds (5); // execute once every 5 seconds // Trigger trigger = new SimpleTrigger ("trigger1", "group1", "job1", "group1", ts, null, // SimpleTrigger. repeatIndefinitely, interval); // run once every several hours. The hourly interval is specified by the IndexIntervalHour parameter in deleetasktrigger = TriggerUt Ils. makeDailyTrigger ("tigger1", 0, 37); // (executed every day) make it run at // Trigger trigger = TriggerUtils. makeHourlyTrigger ("tigger1", 1, 2); // (executed hourly) it is executed twice every hour. // Trigger trigger = TriggerUtils. makeImmediateTrigger ("tigger1", 2, TimeSpan. fromSeconds (5); // (immediate execution) execute once in 5 seconds, a total of 2 executions. That is to say, the task is executed twice in 10 seconds. After these two executions, they are no longer executed. // Trigger trigger = TriggerUtils. MakeMonthlyTrigger ("tigger1", 5); // (executed every month) execute at on January 1, // and many other methods. Trigger. jobName = "job1"; trigger. jobGroup = "group1"; trigger. group = "group1"; sched. addJob (job, true); sched. scheduleJob (trigger); sched. start (); Application. enableVisualStyles (); Application. setCompatibleTextRenderingDefault (false); Application. run (new Form1 (); sched. shutdown (true );}}}


Using Quartz; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. windows. forms; namespace test scheduled task {class TestJob: IJob // here we let the TestJob class inherit the IJob interface and implement this interface. We can see that there is only one Execute method in this interface. {Public void Execute (JobExecutionContext context) {// throw new NotImplementedException (); MessageBox. Show ("the task is executed! "); // We will pop up a" task execution! "in this method !" . }}}


Zookeeper

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.