在asp.net中包含web应用程序中的调度

时间:2011-06-18 07:23:30

标签: asp.net web-applications

我想在web应用程序中定期运行asp.net中的调度过程。

简而言之,我的数据库表有日期&截止日期Hrs.I想要从两个表中计算预期的dateTime,然后定期更新另一个表(插入1000个记录)&也想根据计算结果运行邮件发送过程。

这是应该定期执行的预期程序。

4 个答案:

答案 0 :(得分:2)

Quartz.NET job scheduler library非常适合这类事情。

答案 1 :(得分:0)

您可以使用 Window Service 在后台或日程安排中工作,请参阅以下链接:

Using Timers in a Windows Service

答案 2 :(得分:0)

查看Jeff Atwood中的旧文章: Easy Background Tasks in ASP.NET

基本上,他建议您使用缓存过期机制来安排定时任务。问题是:您的Web应用程序需要运行。如果网站根本没有被呼叫怎么办?好吧,自IIS 7.5以来,您可以随时保持Web应用程序的运行:auto starting web apps。杰夫在评论中表示他的方法很有效,直到他们超过它。他的结论是,对于小型网站来说,这是一个很好的方法。

答案 3 :(得分:0)

这就是我的所作所为:

   public class Email {
        private static System.Threading.Timer threadingTimer;

        public static void StartTimer()
        {
            if (threadingTimer == null)
                threadingTimer = new Timer(new TimerCallback(Callback), HttpContext.Current, 0, 20000);
        }

        private static void Callback(object sender)
        {
            if (/* Your condition to send emails */)
                using (var context = new MyEntities())
                {
                        var users = from user in context.Usere
                                     select user;
                        foreach (var user in users)
                        {
                            // Send an email to user
                        }
                }
        }
    }

您必须将此添加到Application_Start:

    void Application_Start(object sender, EventArgs e)
    {
         EMail.StartTimer();
    }