首页 > 代码库 > Quartz.NET 快速入门
Quartz.NET 快速入门
官网: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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。