I'm pretty new to C# and I was trying to learn about Quartz scheduler. I have been trying to execute the below code but my doubt is why is the scheduler not entering the HelloJob class. Am I doing something wrong?
Apologies if it is a silly mistake but am not able to get any positive result for some time now.
This is my code:
public class Program
{
public static async Task Main(string[] args)
{
StdSchedulerFactory factory = new StdSchedulerFactory();
IScheduler scheduler = await factory.GetScheduler();
CancellationToken stoppingToken = CancellationToken.None;
await DoSomething(scheduler, stoppingToken);
}
public async Task DoSomething(IScheduler scheduler, CancellationToken ct)
{
var job = JobBuilder.Create<HelloJob>()
.WithIdentity("name", "group")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("name", "group")
.WithSimpleSchedule()
.StartNow()
.Build();
await Console.WriteLineAsync("Job is still in Main class")
await scheduler.ScheduleJob(job, trigger, ct);
}
}
public class HelloJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
await Console.WriteLineAsync("Job Entered HelloJob class")
}
}
Scheduler has't been started yet, there is a need to call its
Startmethod. From Quartz docs:like:
(example was taken from here)