简体   繁体   中英

Quartz.NET can invoke my class function if asp.net app pool is idle

suppose i wrote & schedule Quartz.NET job related code in application_start event like this way

public class HelloJob : IJob
    {
        public void Execute(JobExecutionContext context)
        {
            //Send Mail
        }
    }


    public static void ConfigureQuartzJobs()
    {
        // construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory();

        // get a scheduler
        IScheduler sched = schedFact.GetScheduler();
        sched.Start();

        // construct job info
        JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));
        //created trigger which will fire every minute starting immediately
    ITrigger trigger = TriggerBuilder.Create()
          .WithIdentity("myTrigger", "group1")
          .StartNow()
          .WithSimpleSchedule(x => x
              .WithIntervalInSeconds(60)
              .RepeatForever())
          .Build();

        sched.ScheduleJob(jobDetail, trigger);
}

protected void Application_Start()
{
    ConfigureQuartzJobs();
}

so i like to know that my routine will hit after every 60 second if app pool is idle or if no visitor is browsing my web site any page?

my main concern is i need to invoke a specific routine after 60 second if app pool is idle or active. or even no visitor is browsing my web site any page.

so please guide me what should i do? thanks

You can do following without Quartz: 1) In Application_End method check shutdown reason (you are interested in timeout). http://msdn.microsoft.com/en-us/library/system.web.applicationshutdownreason(v=vs.110).aspx

2) When you get the idle timeout reason write and event with specific id to windows event log

3) Go to windows task scheduler. Create new task. Go to triggers. New trigger. in the trigger type combo box choose "On an event". Choose the log, source and event id you write to log. (by default Application)

4) Go to Actions->New->Send Email

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM