views:

151

answers:

3

I am looking for a way to have a script run every day at 5am to delete the contents of a Temp folder. The following is the method I am considering. I would appreciate any thoughts on this or suggestions for other methods. I want to keep everything local, so that there are no external dependencies from outside my account on Discount ASP hosting.

  • Have a textfile containing the datetime of the next desired run (5:00am tomorrow).
  • Have a Datetime cache value that expires after (one hour?)
  • When someone hits the website and the cache is expired, reload the datetime into cache
  • If the Datetime has passed, run the script to be "scheduled" and add 24 hours to the DateTime in the file

Your comments are appreciated.

+1  A: 

You could also create a web service to perform the task, then have a scheduled task call the web service periodically.

John Saunders
+1  A: 

This isn't a good idea, as you are depending on input that might never come to execute an operation which has a need to be performed on a regular basis.

Because of that, you need input from outside of the site (since the site is triggered by requests) to trigger your event, in other words, a scheduler.

You should be using a Scheduled Task for this. If you aren't, then you should have some other process which will send the event to the site (expose a web method perhaps) which on the schedule you desire.

casperOne
+4  A: 

You are on the right way. Here is a good article how to achieve this.

Also, based on your comment, why not use session end event to purge? Also, you can hook to application end as well, just in case.

Sunny