Quartz.NET 快速入門

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   for   

官網:http://www.quartz-scheduler.net/

API:http://www.quartz-scheduler.net/documentation/index.html

快速入門:http://www.quartz-scheduler.net/documentation/quartz-2.x/quick-start.html

 

一個簡單的快速入門樣本

using Quartz.Impl;using System;using Quartz;using System.Threading;namespace QuartzTest1{    class Program    {        static void Main(string[] args)        {           try            {                Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter {Level = Common.Logging.LogLevel.Info};                // Grab the Scheduler instance from the Factory //從工廠的執行個體中擷取 發送器                IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();                // and start it off                scheduler.Start();//啟用發送器                // define the job and tie it to our HelloJob class定義一個job把它交給 HelloJob的類                IJobDetail job = JobBuilder.Create<HelloJob>()                    .WithIdentity("job1", "group1") //job的名稱 和 job所在的組                    .Build();//建立這個job                // Trigger the job to run now, and then repeat every 10 seconds //現在就觸發這個job,並沒隔10秒重複                ITrigger trigger = TriggerBuilder.Create()                    .WithIdentity("trigger1", "group1")//觸發器 名稱和 組                    .StartNow()                    .WithSimpleSchedule(x => x                        .WithIntervalInSeconds(2) //這裡參數為”秒“                        .RepeatForever())                    .Build();                // Tell quartz to schedule the job using our trigger                scheduler.ScheduleJob(job, trigger);//通知到quarts 調度這個job用觸發器                // some sleep to show what‘s happening                //Thread.Sleep(TimeSpan.FromSeconds(60));                // and last shut down the scheduler when you are ready to close your program                //scheduler.Shutdown();//關閉調度            }            catch (SchedulerException se)            {                Console.WriteLine("錯誤記錄檔:"+se);            }            //Console.WriteLine("Press any key to close the application");            //Console.ReadKey();                }    }    public class HelloJob : IJob    {        public void Execute(IJobExecutionContext context)        {            Console.WriteLine("Greetings from HelloJob!-wjw");        }    }}

 

Quartz.NET 快速入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.