OnStart
Let's take a look at our OnStart
method:
public new bool OnStart([CanBeNull] HostControl host) { base.Start(host); _hc = host; _jobScheduler?.Start(); //_logger?.SendInformation(string.Intern("Job scheduler started")); // construct a scheduler factory ISchedulerFactory schedFact = new StdSchedulerFactory(); // get a scheduler IScheduler sched = schedFact.GetScheduler().Result; sched.Start(); // define the job and tie it to our HelloJob class IJobDetail job = JobBuilder.Create<SampleJob>() .WithIdentity("myJob", "group1") .Build(); // Trigger the job to run now, and then every 40 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity("myTrigger", "group1") .StartNow() .WithSimpleSchedule(x => x .WithIntervalInSeconds(40) .RepeatForever()) .Build(); // Schedule the job sched.ScheduleJob(job, trigger); return true;}
What exactly are we doing here? Let's take it one step at a time:
- The first line we encounter is to instantiate the scheduler from the factory
- The second...