Search code examples
c#quartz-schedulershutdown

Scheduler with name "DefaultQuartzScheduler" already exists and scheduler cannot be started after shutdown


Hi I have quartz scheduler in my application.

My scheduler code is like below:

 private void StartImportScheduler()
{
static ISchedulerFactory _schedFact;
static IScheduler _sched;
_sched.Shutdown(true);
_schedFact = new StdSchedulerFactory();
_sched = _schedFact.GetScheduler();
_sched.Start();
}

In my application I have to login and logout application multiple times.

At each logout scheduler shuts down and at each login scheduler starts.

Scheduler is also used in my application at another place too.

When I logout and login again I found the following errors-

Scheduler with name "DefaultQuartzScheduler" already exists scheduler cannot be started after shutdown.


Solution

  • from the documentation:

    Note that once a scheduler is shutdown, it cannot be restarted without being re-instantiated.
    

    If the factory always returns the same instance of the scheduler, that's why you get the error. You could use standby() method instead which temporarily halts the Scheduler's firing of Triggers. When start() is called it brings the scheduler out of stand-by mode.