Quartz.NET remoting - scheduler already exists

时光怂恿深爱的人放手 提交于 2019-12-05 21:39:21

you should write your IScheduler as a singleton

I had a similar issue with the "scheduler already exists". I created a singleton class and I was able move past my issue.

The singleton code looks like this if anybody can use it. The lock is to avoid the issue from before when having more threads trying to get the same instance at once.

using Quartz;
using Quartz.Impl;

namespace MyProject.CommonObjects.Utilities
{
  public static class QuartzFactory
  {
    private static object _locker = new object();
    private static IScheduler _schedulerInstance;

    public static IScheduler SchedulerInstance
    {
      get
      {
        lock (_locker)
        {
          if (_schedulerInstance == null)
            _schedulerInstance = StdSchedulerFactory.GetDefaultScheduler();

          return _schedulerInstance;
        }
      }
    }
  }
}

I found another solution. By giving each scheduler a different name I was able to work around the issue. I find this a better solution than the singleton one.

  NameValueCollection properties = new NameValueCollection
  {
    [StdSchedulerFactory.PropertySchedulerInstanceName] = "MyNewScheduler1"
  };
  StdSchedulerFactory fac = new StdSchedulerFactory(properties);
  _scheduler = fac.GetScheduler();
  _scheduler.Start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!