Just downloaded Quartz.Net, read the documentation which is out of date and have ended up with the code below which I believe is correct. (Let me know if it isn't)
I put this in my Application_Start of my ASP.Net application and the code gets executed but the job does not run. I think I read somewhere about setting Quartz up as a singleton but not sure if I've done that here?
I want to set this up to run daily at 9.00 but for now have used StartNow to check it works.
Please advise what I have to do?
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
}