0

I have a web application and i want to implement scheduler I am using Quartez.Net library

I added the following code to the application in Global.asax

  protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);

        MyScheduler.StartScheduler();
    }

I Created the following class to start my job periodically

public class MyScheduler
 {
      public void StartScheduler()
       {
        // First we must get a reference to a scheduler
        ISchedulerFactory sf = new StdSchedulerFactory();
        IScheduler sched = sf.GetScheduler();

        // computer a time that is on the next round minute
        DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);

        // define the job and tie it to our HelloJob class
        IJobDetail job = JobBuilder.Create<MyJob>()
            .WithIdentity("job1", "group1")
            .Build();

           ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .WithDailyTimeIntervalSchedule(
                    x => x.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(14, 41))
                             .EndingDailyAt(TimeOfDay.HourAndMinuteOfDay(14,43))
                             .WithIntervalInSeconds(30))
                .Build();

        // Tell quartz to schedule the job using our trigger
        sched.ScheduleJob(job, trigger);


        // Start up the scheduler (nothing can actually run until the 
        // scheduler has been started)
        sched.Start();           
      }
   }

I want to know is there is any problem if i leave that scheduler running without stopping it

Mohamed Salah
  • 959
  • 10
  • 40

1 Answers1

1

That's the way it should work since you're running a scheduler. You must be aware of the fact that your application could be shut down because of inactivity and consequently your scheduler wouldn't work.
Phil Haack wrote about it.

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
LeftyX
  • 35,328
  • 21
  • 132
  • 193