Quartz.net的简单工作示例

我正在寻找一个简单的Quartz.net for Console应用程序示例(它可以是任何其他应用程序,只要它足够简单……)。 虽然我在那里,是否有任何包装可以帮助我避免实施IJobDetail,ITrigger等。

有一个人和你做了完全相同的观察,他发表了一篇博文,上面有一个Quartz.net控制台应用程序的简单工作示例。

以下是针对Quartz.net 2.0(最新版)构建的Quartz.net示例。 这项工作的作用是每隔5秒在控制台中写一条短信“Hello Job was execution”。

启动Visual Studio 2012项目。 选择Windows Console Application 将其命名为Quartz1或您喜欢的任何名称。

要求使用NuGet下载Quartz.NET程序集。 右键单击项目,选择“Manage Nuget Packages”。 然后搜索Quartz.NET 。 一旦找到选择并安装。

 using System; using System.Collections.Generic; using Quartz; using Quartz.Impl; namespace Quartz1 { class Program { static void Main(string[] args) { // construct a scheduler factory ISchedulerFactory schedFact = new StdSchedulerFactory(); // get a scheduler, start the schedular before triggers or anything else IScheduler sched = schedFact.GetScheduler(); sched.Start(); // create job IJobDetail job = JobBuilder.Create() .WithIdentity("job1", "group1") .Build(); // create trigger ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever()) .Build(); // Schedule the job using the job and trigger sched.ScheduleJob(job, trigger); } } ///  /// SimpleJOb is just a class that implements IJOB interface. It implements just one method, Execute method ///  public class SimpleJob : IJob { void IJob.Execute(IJobExecutionContext context) { //throw new NotImplementedException(); Console.WriteLine("Hello, JOb executed"); } } } 

来源

  • 原始url
  • archive.org链接

源代码中的文档和示例之间应该足以让您入门。 创建自定义作业时,唯一必须实现的接口是IJob 。 所有其他接口都已经为您实现,或者在quartz.net中不是基本用法所必需的。

构建作业和触发器以使用JobBuilder和TriggerBuilder辅助对象。