简体   繁体   English

如果asp.net应用程序池空闲,则Quartz.NET可以调用我的类函数

[英]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 假设我以这种方式在application_start事件中编写并安排了与Quartz.NET作业相关的代码

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? 所以我想知道,如果应用程序池空闲或如果没有访问者正在浏览我的网站的任何页面,我的例程将在每60秒后触发一次?

my main concern is i need to invoke a specific routine after 60 second if app pool is idle or active. 我主要关心的是,如果应用程序池空闲或活动,我需要在60秒后调用特定的例程。 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). 您可以在不使用Quartz的情况下执行以下操作:1)在Application_End方法中,检查关闭原因(您对超时感兴趣)。 http://msdn.microsoft.com/en-us/library/system.web.applicationshutdownreason(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/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 2)当您获得空闲超时原因时,将具有特定ID的事件和事件写入Windows事件日志

3) Go to windows task scheduler. 3)转到Windows任务计划程序。 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. 选择您要写入日志的日志,源和事件ID。 (by default Application) (默认为应用程序)

4) Go to Actions->New->Send Email 4)转到操作->新建->发送电子邮件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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