简体   繁体   中英

quartz.net job not running in windows server 2008 R2

I created a windows service in c#.net, it uses quartz.net to do a job every hour. it works locally and doesn't have any problem. but when I installed it on server 2008 R2, it doesn't work. it starts and no error. I used event log and I undrestood class JobScheduler works but jobs don't fire. please help me.

     public class JobScheduler
{
    public static void Start()
    {
        try
        {
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            IScheduler scheduler = schedFact.GetScheduler();
            scheduler.Start();
            IJobDetail job = JobBuilder.Create<CheckJob>().WithIdentity("MyJob", "group1").Build();

            ITrigger trigger = TriggerBuilder.Create().WithIdentity("myTrigger", "group1").StartNow().WithSimpleSchedule(s => s.WithIntervalInHours(1).RepeatForever()).Build();



            scheduler.ScheduleJob(job, trigger);
            EventLogging.Log("jobscheduling ok");


        }
        catch (Exception ex)
        {
            EventLogging.Log("jobscheduler:"+ex.Message);

        }
    }
}

In my experience with quartz, you can check a free points,

  1. Inspect the exe property and ensure it is not blocked

  2. Check for the proper connection string

  3. Check if the required files are in correct path

  4. Try to write logs / enable logging to see what's going wrong

You have a variable scope issue, because you are not keeping a reference to the scheduler outside of the Start method. In order for the scheduler to keep running after the Start method finishes running, the scheduler variable needs to be defined as a static variable, and not as a method variable.

You can use the quartz.server that comes with the package download.

https://github.com/quartznet/quartznet

Once you feel comfortable with the framework - then create your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM