Quartz.net C # Tutorials-course FOUR: triggers

Source: Internet
Author: User
Tags net thread

As with jobs, triggers is simple to use, but there are some customization options to understand, otherwise it is difficult to fully play the Quartz.net function. In addition, there are many different types of trigger, can meet the needs of various scheduling. Common Trigger Attributes

All trigger classes have other common properties in addition to the unique Triggerkey attribute. These attribute values are assigned by Triggerbuilder when constructing the trigger definition (described in the example below).

Common properties: Jobkey: Used to uniquely indicate the trigger object when trigger is triggered. STARTTIMEUTC: Indicates when the trigger is scheduled for the first time. Its value is a DateTimeOffset object that defines a moment in the calendar time. Some trigger types, trigger will be triggered at the start, and other trigger will mark a scheduler startup time. This means that you can give trigger a scheduling time, similar to: "January fifth Days", if the STARTTIMEUTC value is April 1, it will be several months before the trigger trigger. ENDTIMEUTC: Indicates when trigger will not be scheduled for execution. That is, if the trigger schedule is fifth a month, and the ENDTIMEUTC value is July 1, then the trigger's last execution time is June 5.

The other properties are discussed in detail below. Priority

If there are a number of worker threads in your quartz.net thread pool, quartz.net may not have enough resources to immediately execute the trigger that is set at the same schedule time. At this point you need to control the quartz.net when there are idle worker threads, which trigger will get execution time. This requires setting the priority for trigger. If you do not set the priority, the default is 5, and you can set any integer value on the priority level, either integers or negative numbers.

Note: Priority values are valid only for trigger that are executed at the same time. The scheduling time of the early trigger regardless of the priority number will be more than the scheduled time of the late trigger first execution.

Note: When a trigger is detected to be restored, its priority is restored to the same priority as before. Misfire Instructions

Misfire means a trigger because his scheduler is turned off to miss its trigger time, or because there are no threads available in the quartz.net thread pool to perform the trigger job. Different trigger types have their respective misfire indicators. By default, the ' Smart policy ' indicator-it will dynamically determine its own behavior based on the type and configuration of trigger. When the scheduler starts
, it finds all triggers that missed the trigger, and then updates triggers based on their respective configured indicators. calendars

The Quartz.net Calendar object implements the ICalendar interface and is associated with trigger when trigger is present in the scheduler. Calendars can be used to remove a specific block of time from a trigger trigger time period. For example, you have a trigger on every weekday 9:30, then add a Calendar to remove all the holidays.

Calendar can be any serializable object that implements the ICalendar interface as follows:

Namespace Quartz
{public
    interface ICalendar
    {
        string Description {get; set;}

        ICalendar calendarbase {set; get;}

        BOOL Istimeincluded (DateTimeOffset TIMEUTC);

        DateTime GETNEXTINCLUDEDTIMEUTC (DateTimeOffset timeutc);
    }
 

Although Calendareven can move from a small to a millisecond time period, usually you may want to remove the whole day, for convenience, Quartz.net defines a Holidaycalendar class.

Calendars must be initialized and registered with Addcalendar () to scheduler. For Holidaycalendar, after initialization, you need to use its addexcludeddate (DateTime date) method to reload the date you want to move out. The same calendar object can be used for multiple triggers:

Calendar Example

    Holidaycalendar cal = new Holidaycalendar ();
    Cal. Addexcludeddate (somedate);

    Sched. Addcalendar ("Myholidays", Cal, false);

    Itrigger t = triggerbuilder.create ()
        . Withidentity ("Mytrigger")
        . Forjob ("Myjob")
        . Withschedule (Cronschedulebuilder.dailyathourandminute (9))//Execute job at 9:30
        . Modifiedbycalendar ("myholidays")//But not on holidays
        . Build ();

    // .. Schedule job with trigger

    itrigger t2 = triggerbuilder.create ()
        . Withidentity ("MyTrigger2")
        . Forjob ("MyJob2")
        . Withschedule (Cronschedulebuilder.dailyathourandminute)//Execute job at 11:30
        . Modifiedbycalendar ("myholidays")//But not on holidays
        . Build ();

    // .. Schedule Job with Trigger2 

The next class describes the details of triggers's construction. Now, once you know that the above code constructs two trigger, each is scheduled for daily execution. But calendar will make them skip scheduling time.

You can see if there is a ICalendar implementation in the Quartz.Impl.Calendar namespace that meets your needs.

«lesson 3 | Lesson 5»

Original

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.