Create a class that impelement IJob classusing System; using Quartz.Impl; using Quartz; namespace quartz { public class MyJob : IJob { public void Execute(IJobExecutionContext context) { Console.WriteLine("Hello"); } } }
create a job and a cron scheduler in main function, and schedule the job with the cron schedulerusing System; using Quartz; using Quartz.Impl; using Quartz.Impl.Triggers; using System.Threading; namespace quartz { class MainClass { public static void Main (string[] args) { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail job2 = JobBuilder.Create
(). WithIdentity("job2", "group1") .Build(); //run every 2 seconds. ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger3", "group1") .WithCronSchedule("0/2 * * * * ?") .Build(); scheduler.ScheduleJob(job2, trigger); Thread.Sleep(30000); scheduler.Shutdown (); Console.ReadKey (); } } }
2015-09-21
C# Scheduler Example - Quartz
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment