Quartz.NET 2.0 作業調度架構使用

來源:互聯網
上載者:User

標籤:winform   style   blog   http   io   color   ar   使用   for   

Quartz.NET是一個開源的作業調度架構,是 OpenSymphony 的 Quartz API 的.NET移植,它用C#寫成,可用於winform和asp.net應用中。它提供了巨大的靈活性而不犧牲簡單性。你能夠用它來為執行一個作業而建立簡單的或複雜的調度。它有很多特徵,如:資料庫支援,叢集,外掛程式,支援cron-like運算式等等。

完成一個Quartz調度需要:調度器(IScheduler)、任務(JobDetail)、觸發器(Trigger)

無需設定檔代碼如下:

using Quartz.Impl;using System;namespace Quartz{    class Program    {        static void Main(string[] args)        {            //調度器構造工廠            ISchedulerFactory factory = new StdSchedulerFactory();            //第一步:構造調度器            IScheduler scheduler = factory.GetScheduler();            scheduler.Start();//啟動調度器            //第二步:定義任務            JobDetailImpl job = new JobDetailImpl("MyJob1", typeof(HandleClass));            //第三步:定義觸發器            ITrigger trigger = TriggerBuilder.Create()                .WithIdentity("t1")//觸發器名稱                .ForJob(job)                .StartNow()                .WithSimpleSchedule(x => x.RepeatForever()                    .WithIntervalInSeconds(1))//1s 執行一次                 .Build();            //將任務與觸發器添加到調度器中:            scheduler.ScheduleJob(job, trigger);        }    }    /// <summary>    /// 工作類    /// </summary>    public class HandleClass : IJob    {        /// <summary>        /// 任務調用的方法        /// </summary>        public void Execute(IJobExecutionContext context)        {            Console.WriteLine("hello work!");        }    }}

源碼地址: Quartz.zip

Quartz.NET 2.0 作業調度架構使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.