Scheduled Tasks in ASP.NET!

I never would have thought there was a way to get around from needing a scheduled task to execute without implementing a windows service or a scheduled task run of a compiled executable.

Well I thought wrong.

Lately I’ve been doing alot of reading to keep up with everything .Net related and have been finding some incredible information, this has got to be one of the most profound things I have found in my ASP.NET experience.

The whole premise of a task scheduler is it needs to be atomic that every predefined interval the scheduler needs to wake up and figure out if it needs to do anything and then sleep until the next interval when it’s finished. Emulating this in ASP.NET would be impossible as far as I ever thought due to the fact that so much of all code execution is all instance based and the server itself will even sleep due to inactivity. Neither of those 2 core functionalities are desirable for a scheduler as it defeats the whole purpose of it.

This is where caching comes in. Yes, you read that right, caching. Not the standard practice of caching data for performance we’re all used to do doing but using the cache to store a cache object with a callback function and near future expiration to create our atomized tick.

Bill Beckelmen on his blog refreshes information that was spawned the whole way back in 2005 on CodeProject and improved from Microsoft’s MVP Omar Zabir’s original idea. Bill wrote Simulate a Windows Service Using ASP.NET to Run Scheduled Jobs

For the basic idea take a look over at Bill’s blog or check back as I might implement a draft of this to test it myself for a project that could potentially use it as a web driven service manager.


2 thoughts on “Scheduled Tasks in ASP.NET!

  1. Chris,

    Thanks for taking a look at my post. I agree, I never thought it was possible until I ran across the article. I’m not sure how robust it is and if I would trust it for something mission critical, but if you need mission critical your probably not on a shared server anyway and can use a windows service. I just want to re-iterate as well that I didn’t write the posted code and don’t take credit for it or the idea. I just posted what I found in the comments to give it some more exposure since I am sure tons of people are looking for the solution it provides. Please let me know what you develop using the idea going forward.

    Best Regards,
    Bill Beckelman

  2. I agree Bill I doubt I’d attempt this on a mission critical service but it has left me wondering if this is a very viable solution to setup nightly jobs to allow IIS to handle the threading of the jobs.

    Basically what I’m thinking this could be amazing for is to setup your jobs to be invoked by an asynchronous web service call and have the scheduled task fire off a bunch of requests to the web service broken down to like a list of IDs from the database to run and have a WCF handle all of the work allowing you to setup a dynamically multithreaded batch job with no need to worry about the code over head of maintaining thread safe code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s