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