Я закончил тем, что сделал функцию помощи GetTrigger
class Program
{
static void Main(string[] args)
{
Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter { Level = Common.Logging.LogLevel.Info };
IJobDetail jobOne = JobBuilder.Create<JobOne>()
.WithIdentity(typeof(JobOne).Name)
.Build();
IJobDetail jobTwo = JobBuilder.Create<JobTwo>()
.WithIdentity(typeof(JobTwo).Name)
.Build();
var jobOneTrigger = GetTrigger(new TimeSpan(0, 0, 5), jobOne);
var jobTwoTrigger = GetTrigger(new TimeSpan(0, 0, 5), jobTwo);
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.ScheduleJob(jobOne, jobOneTrigger);
scheduler.ScheduleJob(jobTwo, jobTwoTrigger);
scheduler.Start();
}
private static ITrigger GetTrigger(TimeSpan executionTimeSpan, IJobDetail forJob)
{
return TriggerBuilder.Create()
.WithIdentity(forJob.JobType.Name+"Trigger")
.StartNow()
.WithSimpleSchedule(x => x
.WithInterval(executionTimeSpan)
.RepeatForever())
.ForJob(forJob.JobType.Name)
.Build();
}
}
public class JobOne : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("JobOne");
}
}
public class JobTwo : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("JobTwo");
}
}