Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run a process every day in a .Net web application without writing a windows service or SQL server jobs

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?

like image 381
Kalpak Avatar asked Sep 08 '09 17:09

Kalpak


1 Answers

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.

like image 146
Jeff Sternal Avatar answered Oct 12 '22 20:10

Jeff Sternal