There are Quartz.Net sheduller and its Listeners, namely TriggerListeners, JobListeners, SchedulerListeners. Which of the students work from the launching stream, and which in their own? Is it possible from the listener or the work itself (Job) to make the main thread perform the action in its (main, main) context?

    1 answer 1

    I don’t quite understand why it is needed, but if you need to pass the environment of the method in which IScheduler initialized, you can create a IJobFactory implementation of IJobFactory and transfer necessary things to its constructor, the main thing is that Dispose should not be IJob before they would be used in IJob

    Example:

     static class Program { static void Main() { var _kernel = new StandardKernel(new DIConfig()); var _scheduler = new StdSchedulerFactory().GetScheduler(); _scheduler.JobFactory = new MyCustomJobFactory(_kernel); // тут добавить триггеры и типы, реализующие IJob Console.ReadKey(); _scheduler.Shutdown(); } } class MyCustomJobFactory : IJobFactory { private readonly IKernel _kernel; public JobFactory(IKernel kernel) { _kernel = kernel ?? throw new ArgumentNullException(nameof(kernel)); } public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { var qwe = Activator.CreateInstance(bundle.JobDetail.JobType, _kernel); return qwe as IJob; } public void ReturnJob(IJob job) { } } 

    Note : in fact, in my code, kernel is a DI container, and it instantiated an IJob implementation with dependency injection through a ctor, in this case kernel is used only for demonstration and anything could be in its place ...

    • what a strange public void method ReturnJob (IJob job) {}, what does it do? in the sense of what is its meaning - sag3ll0