2012-01-11 35 views
11

我正在尋找Quartz.net for Console應用程序 的工作簡單示例(只要足夠簡單,它可以是任何其他應用程序...)。 雖然我在那裏,沒有任何包裝,可以幫助我避免執行 IJobDetail,ITrigger等Quartz.net的簡單工作示例

+1

http://www.quartz-scheduler.net/documentation/quartz-2.x/quick-start。 html – 2016-09-05 15:24:55

回答

0

在源代碼中的文檔和樣品之間應該有足夠讓你開始。創建自定義作業時,必須實現的唯一界面是IJob。所有其他接口已經爲您實施,或者在quartz.net中不需要它們的基本用法。

建立作業和觸發器使用JobBuilder和TriggerBuilder助手對象。

11

有一個人做出了與你完全相同的觀察,並且他發表了一篇博客文章,其中包含一個Quartz.net控制檯應用程序的簡單工作示例。

以下是針對Quartz.net 2.0(最新版)構建的Quartz.net示例。這項工作的作用是每5秒在控制檯上寫一條短信,「Hello Job is executed」。

啓動Visual Studio 2012項目。選擇Windows Console Application。將其命名爲Quartz1或者你喜歡什麼。

要求 下載使用NuGetQuartz.NET組裝。右鍵單擊項目,選擇「管理Nuget包」。然後搜索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<SimpleJob>() 
       .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); 

     } 
    } 

    /// <summary> 
    /// SimpleJOb is just a class that implements IJOB interface. It implements just one method, Execute method 
    /// </summary> 
    public class SimpleJob : IJob 
    { 
     void IJob.Execute(IJobExecutionContext context) 
     { 
     //throw new NotImplementedException(); 
     Console.WriteLine("Hello, JOb executed"); 
     } 
    } 
} 

來源

+1

不幸的是斷開的鏈接。 – Manachi 2015-11-13 05:15:20

+2

我們很幸運,它在archive.org上! https://web.archive.org/web/20150707071411/http://hammadk.com/quartz-net-working-example 把它放在pastie上只是爲了確保: http://pastie.org/10681194 – 2016-01-10 14:26:37