0

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);
        }

    }
  • 1
    I'd suggest not re-inventing the wheel. Somebody has already written a Quartz.Server (windows service) library. http://geekswithblogs.net/TarunArora/archive/2012/11/16/install-quartz.net-as-a-windows-service-and-test-installation.aspx – granadaCoder Mar 05 '15 at 15:28
  • What is the error you're getting? – Nick Patsaris Mar 06 '15 at 13:55
  • The CalendarSync Service service on local computer started then stopped. Some services stop automatically if they are not in use by other services or programs. granadaCoder - Sorry, but I need to code this, and your link does not solve my problem. – Paweł Chojnacki Mar 07 '15 at 11:18
  • possible duplicate of [Windows service on Local Computer started and then stopped error](http://stackoverflow.com/questions/12209075/windows-service-on-local-computer-started-and-then-stopped-error) – stuartd Mar 13 '15 at 17:49

1 Answers1

0

Problem was with Reference libraries. I've had installed version 4.x in Visual Blend folder and the newest in my project. That was causing conflicts. When I created service as a new project and redownloaded all libraries it worked.

So, yes it if perfectly possible to include Quartz.NET in windows service and if for some reason service stops, it's not because of Quartz.