Reputation: 52523
I'm running .NET on a windows box and I would like to have a function run every night at midnight. Of course since HTTP stateless and Windows doesn't have a "cron job" type function (that I know of), I will either have to visit my site myself every night at midnight or just wait for a user to visit the site to rely on it being updated.
Is there an alternative to this that I can create where something will automatically run at a certain time?
Upvotes: 11
Views: 20604
Reputation: 9153
The windows equivalent of cron is At. If you have access to the machine.
Upvotes: 1
Reputation: 9498
Searching for an answer to the same question, I found this post (quartz-net-with-asp-net) with setup instruction for Quartz.NET ("Enterprise Job Scheduler for .NET Platform", from their website) even from inside an ASP.NET application.
Added it here mainly for reference.
Upvotes: 0
Reputation:
I'm also facing the same issue. I want to run ASP.NET with MSSQL at GoDaddy. But they don't have scheule task for windows hosting. After reading the post, I did my own google and found this free web cron job scheduler:
I just tried and it works perfectly...well almost. The job expires in 1 year.
Hope it helps.
Upvotes: 0
Reputation: 2726
If none of the other answers work for you, here's an option:
There are a bunch of server monitoring services out there that will make an http call to your site at regular intervals (every minute if you like). You can get 5 minute intervals for free on some of them.
Create a password protected page, that performs your function (if it hasn't been done yet today) and point that service at it.
At least this way you won't have to write anything additional, and you can rest easy knowing it doesn't rely on your home machine.
Upvotes: 7
Reputation: 32392
Jeff Attwood at some point in the podcast mentioned a dirty hack to use the Cache Expiration Callback to fake this.
He'd insert an item in .Net's Cache, with an expiration set to 2 hours, and a callback to get called once the item expired, and that was his cron.
I think this was the article:
http://www.codeproject.com/KB/aspnet/ASPNETService.aspx?display=Print
It sucks if you ask me, but for a shared hosting solution, I can't think of anything much better.
Also, there are external cron services that you give a URL to and they will "ping" it regularly, like: (these are not free)
http://webcron.org/
http://www.webbasedcron.com/
Upvotes: 5
Reputation: 1531
you can also take a look at Quartz .Net http://quartznet.sourceforge.net/ which is a scheduler
Upvotes: 1
Reputation: 6928
If you have command-line access you could try the "at" command, which is like an ultra-light cron:
http://support.microsoft.com/kb/313565
Upvotes: 1
Reputation: 2115
It looks like GoDaddy has provisions for this, but There Is More Than One Way To Do It: When you install Drupal it needs you to set up a cron job, and I've found out that the project members have documented this step throughly. Go to http://drupal.org/cron for more information, and remember to read http://drupal.org/node/31506 for specific Windows information. If everything else fails, google for "web cron job" and use a commercial "cron job" service. Choose carefully, don't get ripped off.
Upvotes: 0
Reputation: 845
Use the Timer class to create a timer that periodically calls a method to be executed.
A static timer can be started in the Application_Start event in the Global class. Because the timer uses an interval rather than an absolute time, you'll have to calculate the time interval until midnight and set the Interval property accordingly.
Upvotes: 0
Reputation: 340231
Here's a starting point to programmatically add/delete and manage tasks in the Task Scheduler.
http://www.codeproject.com/KB/system/taskscheduler.aspx
Upvotes: 1
Reputation: 3195
I'm pretty sure that Windows' task scheduler can do most things that cron can do. But I might be missing something.
Edit: Reached at Settings -> Control Panel -> Scheduled Tasks
Upvotes: 12