async static Task Main(string[] args)
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<DemoJob>();
serviceCollection.AddScoped<DemoJob2>();
serviceCollection.AddScoped<IDemoService, DemoService>();
var serviceProvider = serviceCollection.BuildServiceProvider();
await ScheduleJob(serviceProvider);
Console.ReadLine();
}
private static async Task ScheduleJob(IServiceProvider serviceProvider)
{
var props = new NameValueCollection
{
{ "quartz.serializer.type", "binary" }
};
var factory = new StdSchedulerFactory(props);
var sched = await factory.GetScheduler();
await sched.Start();
sched.JobFactory = new DemoJobFactory(serviceProvider);
var job = JobBuilder.Create<DemoJob>()
.WithIdentity("myJob", "group1")
.Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(5)
.RepeatForever())
.Build();
await sched.ScheduleJob(job, trigger);
sched.JobFactory = new DemoJob2Factory(serviceProvider);
var job2 = JobBuilder.Create<DemoJob2>()
.WithIdentity("myJob2", "group2")
.Build();
var trigger2 = TriggerBuilder.Create()
.WithIdentity("myTrigger2", "group2")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(5)
.RepeatForever())
.Build();
await sched.ScheduleJob(job2, trigger2);
}
DemoJob2 会执行两遍,DemoJob不会执行
这个问题我也遇到了,有没有解决方案?