ASP.NETIf you have ASP code that you want to run on a scheduled basis, there is a way to do so that avoids you having to compile your code into a Console Application (or use a Console Application to call your main code in a Web Service on a periodic basis) and run it as a Scheduled Task in Windows. The technique described below leverages the callback feature of ASP.NET cache expiration to trigger the running of your desired code on a periodic basis. One key advantage of using this technique is that you have a tighter code base (without having to branch out into Console Application) that is easier to maintain and deploy. Another main advantage is that you can implement data-driven (robust and easy to maintain) scheduling rules instead of having your scheduling logic embedded within a Windows Scheduled Task (which has its own set of administrative burdens).
The Web Page (A) with frequent visitor traffic calls a Web Service Procedure (B) every time the web page loads. It is best if you use a web page that gets a page view approximately every minute. If the web page you use does not get frequent visitor traffic, then you will not be able to run your scheduled code with precise timing. [sample code] The Web Service Cache Procedure (B) stores a dummy value in cache for a specified time interval and defines a Delegate Procedure (C) to be called upon cache expiration. This code first checks for the existence of the dummy value in cache; if it does not exist, then the value is inserted into cache and set to expire in an amount of time that represents the periodicity with which you want your scheduled code to run. [sample code] The Delegate Procedure (C) calls a Web Service Procedure (D) to establish an HTTPContext, which is essential for proper subsequent code execution. It is important to appropriately set the timeout property of this web service call; the default value of 90 seconds may not be enough time for your scheduled code to finish running. [sample code] The Web Service Run Procedure (D) automatically establishes HTTPContext and calls a Scheduled Procedure (E) that contains the main code that should be run. [sample code] The Scheduled Procedure (E) executes the code that is to be run automatically at periodic intervals. Now that you have code that fires on a routine basis, you can wrap this code within custom processing logic to implement complex rules that dictate valid processing times. [sample code] |
about
contact
rg -at- ryangorer.com
tags
syndication
creations
|