简体   繁体   English

ASP.NET脚本“调度”问题

[英]ASP.NET script “scheduling” question

I am looking for a way to have a script run every day at 5am to delete the contents of a Temp folder. 我正在寻找一种方法让每天凌晨5点运行一个脚本来删除Temp文件夹的内容。 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. 我希望将所有内容保留在本地,以便在我的帐户外部没有折扣ASP托管的外部依赖项。

  • Have a textfile containing the datetime of the next desired run (5:00am tomorrow). 有一个包含下一个所需运行的日期时间的文本文件(明天上午5:00)。
  • Have a Datetime cache value that expires after (one hour?) 是否有一个Datetime缓存值(一小时后到期)?
  • 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 如果已经过了Datetime,请运行脚本以进行“计划”,并将24小时添加到文件中的DateTime

Your comments are appreciated. 您的意见表示赞赏。

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. 此外,您也可以挂钩到应用程序端,以防万一。

您还可以创建Web服务来执行任务,然后让计划任务定期调用Web服务。

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. 如果你不是,那么你应该有一些其他的过程,将事件发送到网站(也许是一个网络方法),按照你想要的时间表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM