0
我正在構建一個Orchard CMS網站項目,我需要安排一些工作,將數據存儲在數據庫中,所以我在Orchard.Web的Global.asax中使用Quartz.NET作爲如下:在Orchard CMS中使用Quartz.NET
protected void Application_Start() {
RegisterRoutes(RouteTable.Routes);
_starter = new Starter<IOrchardHost>(HostInitialization, HostBeginRequest, HostEndRequest);
_starter.OnApplicationStart(this);
ISchedulerFactory sf = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = sf.GetScheduler();
sched.Start();
var job = JobBuilder.Create<JobWorker>()
.WithIdentity("job1", "group1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartAt(DateTime.Now)
.WithCronSchedule("5 0/1 * * * ?")
.Build();
sched.ScheduleJob(job, trigger);
}
而且JobWorker類 - 被放置在同一級別的文件夾中的Global.asax Orchard.Web:
public class JobWorker : IJob, IDependency {
private readonly ISchedulerService _schedulerService;
public JobWorker (ISchedulerService schedulerService) {
_schedulerService = schedulerService;
}
public void Execute(IJobExecutionContext context) {
_schedulerService.ExecuteJob();
}
}
在調試輸出控制檯,如下不過,我已經收到了成效:
A first chance exception of type 'System.ArgumentException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
The thread '<No Name>' (0x2278) has exited with code 0 (0x0).
The thread '<No Name>' (0x3368) has exited with code 0 (0x0).
The thread '<No Name>' (0x22a8) has exited with code 0 (0x0).
The thread '<No Name>' (0x2bc8) has exited with code 0 (0x0).
我試過在web mvc 4項目中使用這段代碼 - 而不是果園 - 並且它工作正常。因此,我認爲問題出在Orchard CMS。 我該怎麼辦?我只需要一個計時器來反覆調用SchedulerService中的方法ExecuteJob()!
哇,它真的比使用Quartz.NET更簡單:) –
確實是:-)。 – Piedone