Schedule Using Quatz .NET

Follow these steps
  1. Add a first reference of Quartz.dll in your web application.
  2. Create a function which you want to execute repeatedly on a scheduled time.

    Call the created function in same class

    example
    1. public void Execute(IJobExecutionContext context) {  
    2.     this.ScheduledTask();  
    3. }  
  3. Create a job (ex:name  JobScheduler)(Function).

    example
    1. public static void Start() {  
    2.     // define the job and tie it to our HelloJob class  
    3.     IJobDetail job = JobBuilder.Create < EmailJob > ()  
    4.         .WithIdentity("myJob""group1"// name "myJob", group "group1"  
    5.         .Build();  
    6.   
    7.     // Trigger the job to run now, and then every 40 seconds  
    8.     ITrigger trigger = TriggerBuilder.Create()  
    9.         .WithIdentity("myTrigger""group1")  
    10.         .StartNow()  
    11.         .WithSimpleSchedule(x => x  
    12.             //.WithIntervalInSeconds(300)  
    13.             .WithIntervalInMinutes(20)  
    14.             .RepeatForever())  
    15.         .Build();  
    16.   
    17.     // Tell quartz to schedule the job using our trigger  
    18.     ISchedulerFactory sf = new StdSchedulerFactory();  
    19.     IScheduler sc = sf.GetScheduler();  
    20.     sc.ScheduleJob(job, trigger);  
    21.     sc.Start();  
    22. }  
  4. Add Global.asax.
    1. protected void Application_Start(object sender, EventArgs e) {  
    2.     JobScheduler.Start();  
    3. }  
That's it. Now, when you execute this code, the function will work repeatedly on the scheduled time.
Ebook Download
View all
DevOps
Read by 0 people
Download Now!
Learn
View all