Job Scheduling framework Quartz. NET 2.0 StepByStep (2)

Source: Internet
Author: User

Through the previous article, I believe that you have a basic understanding of Quartz. Net and can establish the simplest service. This article describes how to set Trigger conditions for a service.

According to the scenario, I usually encounter the following situations at work:

1. Execute when the service starts

This Trigger has been used in the previous example. If you do not need to talk about it, directly add the code.

ITrigger trigger = TriggerBuilder.Create().StartNow().Build()

2. Round-Robin execution within a specified interval

Using SimpleTriggerImpl in the framework, you can easily construct this type of trigger. The following lists several frequently-used constructor loads:

  • SimpleTriggerImpl (string name, int repeatCount, TimeSpan repeatInterval)
  • SimpleTriggerImpl (string name, DateTimeOffset startTimeUtc, DateTimeOffset? EndTimeUtc, int repeatCount, TimeSpan repeatInterval)

For example:

View Code

    SimpleTriggerImpl(string name, int repeatCount, TimeSpan repeatInterval)
SimpleTriggerImpl(string name, DateTimeOffset startTimeUtc,
DateTimeOffset? endTimeUtc, int repeatCount, TimeSpan repeatInterval)

The trigger indicates that the start time is "Start now (UTCNOW required)" + "End Time" + "repeat count 1" (note that the repeat count JOB runs twice) + "Round Robin interval" is 10 seconds.

3. daily round robin

Using the self-contained DailyTimeIntervalTriggerImpl in the framework, you can easily construct this type of trigger. The following lists several frequently used constructor loads:

  • DailyTimeIntervalTriggerImpl (String name, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval)
  • DailyTimeIntervalTriggerImpl (string name, DateTimeOffset startTimeUtc, DateTimeOffset? EndTimeUtc, TimeOfDay startTimeOfDayUtc, TimeOfDay endTimeOfDayUtc, IntervalUnit intervalUnit, int repeatInterval)

For example:

View Code

DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl("DailyTimeIntervalTrigger",DateTimeOffset.UtcNow,null, new TimeOfDay(1, 0, 0), new TimeOfDay(22, 01, 00), IntervalUnit.Minute, 1);
trigger.DaysOfWeek.Add(DayOfWeek.Monday);

The trigger indicates that the start time is immediate (UTCNOW is required) + the end time is none + each day, and the end time is each day + round robin per minute + repeated times 1 + only executed per Monday

4. complex time settings

If you want to build a time setting that is as flexible as SqlServerJob settings, you need to use the CronTriggerImpl class. The method is very simple. You can simply put the Cron expression in the structure.

ITrigger trigger = new CronTriggerImpl("CronTrigger", "TriggerGroup1", "0 0 12 * * ?");

This trigger means that it is executed at every day.

Note: This part of the younger brother did not have a deep understanding, and this part of the API has not been modified, so he will not be able to make a shift. Search for Cron expression/Cron expression by yourself

 

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.