本文介绍了在ASP.NET计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个每天运行两次任务调度。我实现了使用CacheItemRemovedCallaback任务调度程序,如并的。我有一个功能,使管理员修改的预定时间,节省他们在Application变量:

 保护无效UpdateSchedule(对象发件人,EventArgs的发送)
{
    Button按钮=发送者的按钮;
    如果(button.ID ==scheduleButton1)
    {        Application.Lock();
        应用[buildSchedule1] = GetScheduleTime1;
        Application.UnLock();
    }
    否则,如果(button.ID ==scheduleButton2)
    {
        Application.Lock();
        应用[buildSchedule2] = GetScheduleTime2;
        Application.UnLock();
    }
    HttpRuntime.Cache.Remove(Global.DummyCachekey); //删除当前计划任务,并设置新的时间
 }

和上Global.aspx我有:

 保护无效的Application_Start(对象发件人,EventArgs的发送)
{
    Application.Lock();
    应用[buildSchedule1] =新的时间跨度(10,00,0); //默认时间
    应用[buildSchedule2] =新的时间跨度(16,00,0); //默认时间
    Application.UnLock();
    SheduleTask();
};

现在的问题是,由于某种原因(可能是由于应用程序池回收)的计划时间得到恢复,甚至一些次任务将不会在预设时间启动。

我发现,提及的Windows服务或Windows任务调度解决方案,但因为我需要能够让管理员通过Web应用程序配置的时代,这并不为我工作。 (我搜索了这一点,但找不到任何东西)。


解决方案

That's what you should be using. A web application doesn't "always run." It responds to requests, that's all. Unless something is actively making a request to the website, it's not doing anything.

Sure it does. More than one application can share a single database. In this case you'd have two applications:

  • A Web Application where users can login and maintain the data related to the scheduled tasks.
  • A Windows Service (or scheduled Console Application) which runs in the background on the server and executes the configured tasks which it reads from the database.

这篇关于在ASP.NET计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 00:44
查看更多