简体   繁体   中英

IJobDetail job = JobBuilder.Create in same instance. Quartz.NET

If I will not create empty constructor my Execute will not work.

My Code

 public class CalculateManager : ICalculateManager, IJob { static IStrongDataRepository _strongDataRepository; private readonly ICalculateProtocolOne _calculateOne; private Dictionary<string, CalculateModel> _resultDictionary; public CalculateManager(IStrongDataRepository strongDataRepository, ICalculateOne calculateOne) { _calculateOne = calculateOne; _resultDictionary = new Dictionary<string, CalculateModel>(); this.Start(); } public async Task Execute(IJobExecutionContext context) { Console.WriteLine("Here"); var x = _resultDictionary; } public CalculateManager() { } public async void Start() { TimeSpan startTime = new TimeSpan(16, 36, 0); DateTime now = DateTime.Today.Add(startTime); IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); await scheduler.Start(); IJobDetail job = JobBuilder.Create<CalculateManager>().Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .StartAt(now) .WithSimpleSchedule(x => x .WithIntervalInMinutes(2) .RepeatForever()) .Build(); await scheduler.ScheduleJob(job, trigger); }

If I will not create empty constructor. My quarz build will not work. But in this way I have two different instance. In this var x = _resultDictionary; I have null. But in real when it create with all necessary interfaces in first instance thre are in _resultDictionary a lot off results from calculate. How I need to create IJobDetail job that it use the same instance.

I created a static variable in class static List<CalculateManager> _instanceList = new List<CalculateManager>() ;

And put to this list all instance. When Quartz.NET start Execute. It is starting Execute on instace where constcutor without param. And I fine my Instatce such way.

var instance = _instanceList[0];

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