刚刚下载 Quartz.Net,阅读过时的文档,最后得到了我认为正确的代码。(如果不是,请告诉我)
我把它放在我的 ASP.Net 应用程序的 Application_Start 中,代码被执行但作业没有运行。我想我在某处读到过关于将 Quartz 设置为单例的信息,但不确定我是否在这里做到了?
我想将其设置为每天 9 点运行,但现在已经使用 StartNow 来检查它是否有效。
请指教我该怎么办?
private void StartScheduler()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = schedulerFactory.GetScheduler();
scheduler.Start();
IJobDetail jobDetail = JobBuilder
.Create()
.OfType(typeof(DBCleanUpJob))
.WithIdentity(new JobKey("test", "1"))
.Build();
var trigger = Quartz.TriggerBuilder.Create()
.ForJob(jobDetail)
.WithIdentity(new TriggerKey("test", "1"))
.WithSimpleSchedule()
.StartNow()
.Build();
//.WithDailyTimeIntervalSchedule(x=>x.StartingDailyAt(new TimeOfDay(09,00)));
scheduler.ScheduleJob(jobDetail, trigger);
}
public class DBCleanUpJob : IJob
{
private IDocumentSession DocumentSession;
public DBCleanUpJob(IDocumentSession DocSession)
{
DocumentSession = DocSession;
}
#region IJob Members
public void Execute(IJobExecutionContext context)
{
throw new NotImplementedException();
}
#endregion
}