Follow these steps
Add a first reference of Quartz.dll in your web application.
Create a function which you want to execute repeatedly on a scheduled time.
Call the created function in same class
example
1 2 3 |
public void Execute(IJobExecutionContext context) { this.ScheduledTask(); } |
Create a job (ex:name JobScheduler)(Function).
example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static void Start() { // define the job and tie it to our HelloJob class IJobDetail job = JobBuilder.Create < EmailJob > () .WithIdentity("myJob", "group1") // name "myJob", group "group1" .Build(); // Trigger the job to run now, and then every 40 seconds ITrigger trigger = TriggerBuilder.Create() .WithIdentity("myTrigger", "group1") .StartNow() .WithSimpleSchedule(x => x //.WithIntervalInSeconds(300) .WithIntervalInMinutes(20) .RepeatForever()) .Build(); // Tell quartz to schedule the job using our trigger ISchedulerFactory sf = new StdSchedulerFactory(); IScheduler sc = sf.GetScheduler(); sc.ScheduleJob(job, trigger); sc.Start(); } Add Global.asax. protected void Application_Start(object sender, EventArgs e) { JobScheduler.Start(); } |
That’s it. Now, when you execute this code, the function will work repeatedly on the scheduled time.