如何在ASP.net中安排任务? [英] How do I schedule tasks in ASP.net?

查看:201
本文介绍了如何在ASP.net中安排任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 ASP.net(C#)中开发一个站点,并具有以下要求:

I am developing a site in ASP.net (C#) and have the following requirement:

该站点应该每晚从RSS提要中获取数据,执行一些计算并使用计算出的值更新数据库.如何在共享托管环境中实现此目标?

The site should fetch data from an RSS feed every night, perform some calculations and update the DB with the calculated values. How can I achieve this in a shared hosting environment?

我通常会得到一个答案,那就是拥有一个可以执行此操作的Windows服务,但是我不能使用它,因为不允许我在共享托管环境中运行Windows服务.

The answer that I usually get is to have a Windows Service that does this but I cannot use this as I am not allowed to run Windows Services in my shared hosting environment.

我发现的另一种替代方法是使用HttpRuntime.Cache,如中所述https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

The other alternative that I found was to use the HttpRuntime.Cache as described in https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

但是,这种方法似乎有很多弊端.还有其他方法吗?

However that approach seems to have a lot of cons. Is there any other approach?

推荐答案

在某些(最多?)共享的托管服务提供商(至少是我使用的提供商)中,它们允许您通过控制面板安排任务.我知道Discountasp.net也有机架空间.

At some (most?) shared hosting providers, at least the ones I have used, they allow you to schedule tasks through their control panel. I know discountasp.net does and rackspace as well.

如果提供者确实具有此功能,请提供者在指定的时间调用/加载特定的asp.net网页,然后执行其工作.对于许多小任务,这将是阻力最小的路径.

If you provider does have that capability, have it call/load a certain asp.net web page at the designated time, and do its work. For a lot of small tasks, this will be the path of least resistance.

如果它不提供此功能,并且您不愿意切换提供程序,则始终可以从不在您的ISP的计算机上运行计划任务(使用Windows服务器中的内置任务)因为您可以从中访问数据库.我过去也曾使用过这种方法.任何在正确的时间可靠启动的机器都可以.

If it doesn't provide that capability, and you are not willing to switch providers, you can always run a scheduled task (use the built in one in windows server) from a machine that is NOT at your ISP, as long as you can get to the database from it. I have used this method as well in the past. Any machine that is reliably on at the right time will do.

这篇关于如何在ASP.net中安排任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆