Microsoft Windows Services (3) Use quartz.net timed tasks

Source: Internet
Author: User

Quartz is opensymphony Open source organization in the Job scheduling field another open-source project, Quartz.net is the transplant version of Quartz. Quartz can be used to create a simple or complex program that runs 10, hundreds, or even tens of thousands of jobs.

Official website Tutorial: http://www.quartz-scheduler.net/documentation/index.html

  

Advantages:

1. Full, start time, interval, number, end time can be specified.

2. Convenient. There is no need to consider a variety of threading issues.

Download:

Install-package Quartz

  

  

Development:

1.job 2.trigger 3.scheduler

Job: A task item that defines what to do

Implement the Ijob interface. There is only one way.

  

class Samplejob:ijob    {        publicvoid  Execute (ijobexecutioncontext context)        {            File.appendalltext (  "D:\\1.txt" "good");        }    }

Trigger: Trigger that defines how many times to execute .

Constructor: Public Simpletriggerimpl (string name, String group, DateTimeOffset STARTTIMEUTC, DateTimeOffset? ENDTIMEUTC, int RepeatCount, TimeSpan repeatinterval);

  

The ctor can be used to invoke a new trigger

Scheduler: Scheduler, scheduling triggers and tasks to combine

  

var New stdschedulerfactory (); var sched = Factory. Getscheduler ();

Perform:

A. Wrap the ijob into Ijobdetail, through the public Jobdetailimpl (string name, Type jobType);

B. Call the IScheduler interface scheduling method: DateTimeOffset schedulejob (Ijobdetail jobdetail, Itrigger Trigger);

C. Call the IScheduler interface Start method: void Start (), or void startdelayed (TimeSpan delay);

  

Stop it:

Call IScheduler interface Start method: void Shutdown ();

code Download: Click to download

  

Microsoft Windows Services (3) Use quartz.net timed tasks

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.