How do I schedule tasks in ASP.net?

2019-04-11 13:29发布

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

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?

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.

The other alternative that I found was to use the HttpRuntime.Cache as described in http://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?

2条回答
来,给爷笑一个
2楼-- · 2019-04-11 13:55

Windows Scheduled Tasks:

Impossible in shared hosting if you don't have any dedicated resource. Very limited.

Using hacks like Windows Scheduled Tasks and Control Panel abilities are not nice solutions. They sucks most of the time, they was a headache for us due this years.

Scheduling Web Service:

You can use ATrigger scheduling service in shared hosting. A .Net library is also available to create scheduled tasks without overhead.

Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.

查看更多
你好瞎i
3楼-- · 2019-04-11 14:03

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.

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.

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.

查看更多
登录 后发表回答