I am currently working on some Windows Service that will sync Calendars every 10 minutes. I have written console application that does this, but when I try to implement it as a Windows Service it breaks during start. When I remove code responsible for use of Quartz.NET library, service starts and logs everything fine. Every time when new Job is implemented, I'm getting windows message:
The CalendarSync service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs.
Is there any reason why can't I use this library in windows service?
protected override void OnStart(string[] args)
{
LogLibrary.Logs.WriteErrorLog("Calendar service started");
OnStartDo();
}
private static void OnStartDo()
{
try {
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<Job>()
.WithIdentity("job1", "group1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
scheduler.ScheduleJob(job, trigger);
}
catch (SchedulerException se)
{
LogLibrary.Logs.WriteErrorLog(se);
}
}