tags:

views:

2469

answers:

13

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?

Thanks

+6  A: 

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

Adrien
Task scheduler is the way to go.
Greg D
i talked to my host and they said they don't have anything like this... is there something i can write in code?
Jason
does anyone know how to do this w/godaddy.com hosting?
Jason
Schedule something on your home box to do a wget http://yourdomain/ at midnight. I have a godaddy account, when I get home I'll see if I can do anything with scheduling things. 'Tho my godaddy box is Linux.
Adrien
i called godaddy and they said they don't have a "task scheduler" for windows or anything like it... so i have to create a desktop app to call my site at midnight? great.
Jason
The perils of virtual hosting!
ChristianLinnell
Yep ... Now, I'm not sure why someone downvoted me for this one... Odd.
Adrien
A: 

Here's a starting point to programmatically add/delete and manage tasks in the Task Scheduler.

http://www.codeproject.com/KB/system/taskscheduler.aspx

Vinko Vrsalovic
A: 

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.

Tom
A: 

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.

codehead
that first link is only for linux setups, i saw that. i don't have drupal installed
Jason
That's not a drupal-specific solution, it's just that the Drupay guys have done a great job documenting the alternatives extensively.
codehead
+1  A: 

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/

Daniel Magliola
interesting... although neither of those two bottom links you posted are free :\
Jason
Oops! Webcron.org WAS free, for sure, i've used it in the past. Corrected the answer, thank you.
Daniel Magliola
+1  A: 

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

Andrew Duffy
no command line access :(
Jason
+1  A: 

you can also take a look at Quartz .Net http://quartznet.sourceforge.net/ which is a scheduler

Emmanuel
i looked at this, but is it for desktop apps only or is this something you can run on a website? i just don't see how it would work on a website...
Jason
A: 

Why not install cygwin and use cron itself?

here is a pdf guide on setting it up:

http://csc.csudh.edu/kleyba/cygwin-cron.pdf

John T
+2  A: 

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.

Nik
A: 

Hello,

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.

http://www.setcronjob.com/

Hope it helps.

pretty cool resource, although the free acct expires after 3mos not 1 year. not bad tho if you don't mind a little maintenance
Jason
opps. yes it's 3mths. 1 yr are for those paid accts.But, well at least we can manually recreate the cron jobs every 3 mths.Anyways, for the 1yr expiry date, its min $5 for 10 cron jobs. Not too bad :)any1 else has other free cron job sites to recommend?
A: 

If you use dotnetnuke, try this: http://www.wwwcoder.com/tabid/68/type/art/parentid/224/site/6401/default.aspx

A: 

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.

Oliver
A: 

You could use a tool like WebCron:

http://barebonescms.com/documentation/webcron/

Basically, it fakes 'cron' on hosts that don't provide access to a task scheduler. All code resides on your server, thus no need for a third-party.

While it isn't .NET, you should see if your hosting provider offers PHP 5.2 or later. If they do, you're golden.

WebCron