1

I use Quartz lib for executing some tasks by schedule on my ASP.NET MVC project. I initialize my Jobs into method Application_Start of Global.asax file. But after some time Quartz was stopped because method Application_End was executed.

Variables were declared as static:

public static ISchedulerFactory scheduleFactory = new StdSchedulerFactory();

public static IScheduler scheduler = scheduleFactory.GetScheduler();

Here is how Quards's Jobs were initialized:

IJobDetail jobSender = new JobDetailImpl("jobSender", "MailGroup", typeof(JobMailSender));

ITrigger triggerSender = new CronTriggerImpl("triggerSender", "SenderGroup", "jobSender", "MailGroup", "0 0/30 * * * ?");

scheduler.ScheduleJob(jobSender, triggerSender);

scheduler.Start();

I have found the reason why it happens. When all user's sessions will cease to exist and server doesn't have active user's sessions then method Application_End will execute.

I have created new Quartz's job which opens the site every 15 min and as result new user session will create on server. But still method Application_End is called from time to time.

Is anyone faced with a similar problem? Maybe web.config has some settings that would not be executed method Application_End, even if there are no active sessions on the server?

STW
  • 44,917
  • 17
  • 105
  • 161
AlexBel
  • 11
  • 5

2 Answers2

2

I have found that running Quartz inside of IIS can cause problems including this. You are probably getting the Application_End because the application pool is recycling.

We got away from this problem by installing quartz as a service on the same machine, and access that service from the website through the remote proxy of Quartz.

The following link might help: Use one windows service to execute jobs and two web applications to schedule jobs

Community
  • 1
  • 1
Thierry
  • 1,031
  • 7
  • 16
0

In our application we were also facing the same problem that Application_End was called after some time or when the Web Server was Idle, and after which on next activity Application_Start was called again, and schedule was executed again and again.

We ended up by having a simple table in our database say cron_schedule, which was used to maintain the log of Quratz runs. And in our trigger method, we first checked if the last execution time present in the database meets our execution criteria, only then execute the trigger, otherwise simply return or just make a log, so that we may know that schedule was executed but did nothing.

AUR
  • 623
  • 7
  • 14