有没有办法天天在.NET Web应用程序运行的过程,而无需编写Windows服务或SQL服务器作业 [英] Is there a way to run a process every day in a .Net web application without writing a windows service or SQL server jobs

查看:105
本文介绍了有没有办法天天在.NET Web应用程序运行的过程,而无需编写Windows服务或SQL服务器作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在ASP.Net应用程序,一个.net过程中应每天在指定的时间自动调用。这个过程需要与数据库(SQL Server 2005的)相互作用,并产生一个每天计费。我们使用一个共享的主机,因此我们不能够创建一个Windows服务或创建SQL Server作业。这怎么可能无需用户干预实现的?


解决方案

您可以尝试的此处描述的技术,在计算器本身使用的(或至少它用在这里在一个点)。简而言之:


  

      
  1. 在启动时,添加项目到HttpRuntime.Cache具有固定
      过期。

  2.   
  3. 当缓存项到期,做你的工作,如WebRequest的或有什么
      你。

  4.   
  5. 该项目重新添加到具有固定到期缓存。

  6.   

要让它在特定的时间,而不是间隔运行,可以降低间隔只需修改你的工作方法检查时间本身。


由于上文附注链接的原始文章的评论,这不是一个完美的解决方案,也没有人应在一个适当的调度技术preFER,如果有的话。见<一href=\"http://stackoverflow.com/questions/1434284/when-does-asp-net-remove-expired-cache-items/1442211#1442211\">When是否Asp.Net删除过期缓存项?获取一些额外的资格。

We require that in a ASP.Net application, a .Net process should be invoked every day at a specified time automatically. This process needs to interact with the database (SQL Server 2005) and generate billing on a daily basis. We are using a shared hosting hence we are not able to create a windows service or create SQL Server jobs. How can this be achieved without user intervention?

解决方案

You could try the technique described here, used at StackOverflow itself (or at least it was used here at one point). In a nutshell:

  1. At startup, add an item to the HttpRuntime.Cache with a fixed expiration.
  2. When cache item expires, do your work, such as WebRequest or what have you.
  3. Re-add the item to the cache with a fixed expiration.

To get it to run at a specific time instead of an interval, you could lower the interval and simply modify your working method to check the time itself.


As the comments in the original article linked above note, this isn't a perfect solution, and no one should prefer it over a proper scheduling technique if one is available. See When Does Asp.Net Remove Expired Cache Items? for some additional qualifications.

这篇关于有没有办法天天在.NET Web应用程序运行的过程,而无需编写Windows服务或SQL服务器作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆