In ASP.NET can I schedule an .ashx page to run at a certain time of the day?

Go To StackoverFlow.com

0

I'm curious if it is possible to schedule my page, let's call it, Test.ashx to run, say at 2 am every day on IIS, using ASP.NET? (Pretty much what Cron Job does for PHP/Linux system.)

PS1. I need this page to perform a custom operation on the SQL Database table. (Note that I don't have direct access to IIS, or SQL Server itself. I'm writing a web app that needs to incorporate this functionality for a client.)

PS2. I program using C# if that matters.

2012-04-04 05:52
by ahmd0
There is NO robust way to make an ASP.NET application/ashx/whatever behave similar to cron due to several aspects - on being the fact that IIS can recycle an app domain anytime. Use a Windows Service for such things - Yahia 2012-04-04 05:55
I'm using simply Task Scheduler from Windows to ask for a page, but my task is trivial (it is not a big problem if one day it doesn't run - mslliviu 2012-04-04 06:50


1

There is always more than one way to achieve a thing. To perform a custom operation on SQL Database table on a periodic basis, you can schedule a SQL job. Look at this SO answer for more details

https://stackoverflow.com/a/5471440/30594

Update:

Check this link to know how background schedulers can be done in ASP.NET http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

Another way to achieve is to use Windows Task Scheduler to invoke the .ashx periodically

2012-04-04 06:43
by Ramesh
Is there any way to do this from ASP.NET - ahmd0 2012-04-04 06:47
If you insist on ASP.NET (which I really don't know why) you can place .ashx in the IIS and use Windows scheduler to invoke it. When invoked it can do the necessary actions. But, I don't think you can guarantee that it would be run only once and can be invoked by any one else also - Ramesh 2012-04-04 06:50
Again, I need to automate this task (i.e. manually configuring SQL Server via SQL Server Agent is not an option) and thus my idea to do this through a script. Thanks for the link - ahmd0 2012-04-04 07:34
@ahmd0 The cache link is interesting but unsure if its advisable given your requirement - once a day at a given time (see comment on app recycling). The option on using Task Scheduler should be your best bet (on a PC that you control, not necessarily on the box with IIS). Your web host (assumed) may also have options for you to schedule web jobs (e.g. requesting some web page on a given schedule) - EdSF 2012-04-04 07:55
Ads