コード例 #1
0
        public static async Task StartAsync <T>(string cronExp, string jobName, string triggerName, string groupName,
                                                AppEntity appEntity) where T : IJob
        {
            JobDataMap jobDataMap = new JobDataMap();

            jobDataMap.Put("AppEntity", appEntity);
            DateTimeOffset runTime = DateBuilder.EvenSecondDate(DateTime.Now);
            IJobDetail     job     = JobBuilder.Create <T>().WithIdentity(jobName, groupName).UsingJobData(jobDataMap).Build();
            ITrigger       trigger = TriggerBuilder.Create().WithIdentity(triggerName, groupName).WithCronSchedule(cronExp)
                                     .StartAt(runTime).Build();
            ISchedulerFactory factory   = new StdSchedulerFactory();
            IScheduler        scheduler = await factory.GetScheduler();

            await scheduler.ScheduleJob(job, trigger);

            await scheduler.Start();
        }
コード例 #2
0
        public static async Task StartAsync <T>(TimeSpan ts, string jobName, string triggerName, string groupName,
                                                AppEntity appEntity) where T : IJob
        {
            JobDataMap jobDataMap = new JobDataMap();

            jobDataMap.Put("AppEntity", appEntity);
            DateTimeOffset runTime = DateBuilder.EvenSecondDate(DateTime.Now);
            IJobDetail     job     = JobBuilder.Create <T>().WithIdentity(jobName, groupName).UsingJobData(jobDataMap).Build();
            ITrigger       trigger = TriggerBuilder.Create().WithIdentity(triggerName, groupName).StartAt(runTime)
                                     .WithSimpleSchedule(x => x.WithInterval(ts).RepeatForever()).Build();
            ISchedulerFactory factory   = new StdSchedulerFactory();
            IScheduler        scheduler = await factory.GetScheduler();

            scheduler.Context.Put("AppEntity", appEntity);
            await scheduler.ScheduleJob(job, trigger);

            await scheduler.Start();
        }