Recently upgraded my embedded Quartz.net scheduler to 2.x at which point I had to give up on giving my Zero Thread Schedulers unique names and now I have a problem that (very rarely) an object trying to create an instance of ZT scheduler throws an exception because another object already has an instance of ZT scheduler instantiated and since all my ZT schedulers now have the default 'QuartzScheduler' name this throws an exception...
I tried checking for scheduler count using MySchedFactory.AllSchedulers.Count
after calling MySchedFactory = new StdSchedulerFactory(properties)
but the StdSchedulerFactory creates an instance of ZT scheduler as soon as it's instantiated and not when GetScheduler()
method is called so that is a dead end...
I could not find any other way of checking for existing schedulers before instantiating the StdSchedulerFactory
and, as I mentioned already, as soon as it is instantiated, it creates an instance of ZT scheduler so I ended up using a while loop in my catch block which is just a horrible solution so I'm hoping someone knows a better way of checking for existing ZT schedulers...
try
{
//setting properties
MySchedFactory = new StdSchedulerFactory(properties);
BaseScheduler = schedFactory.GetScheduler();
}
catch (Exception ex)
{
var exMsg = ex.InnerException == null ?
ex.Message :
ex.Message + Environment.NewLine + ex.InnerException.Message;
while (exMsg.Contains("Scheduler with name 'QuartzScheduler' already exists"))
{
try
{
MySchedFactory = new StdSchedulerFactory(properties);
BaseScheduler = schedFactory.GetScheduler();
}
catch (Exception vex)
{
exMsg = vex.InnerException == null ?
vex.Message :
vex.Message + Environment.NewLine + vex.InnerException.Message;
}
}
}
Any ideas?