Dave Burke : Freelance .NET Web Developer specializing in Online Communities

First Approach to an ASP.NET Task Scheduler

The subtitle of this post is "Keeping up with Keyvan." The guy is definitely a high octane .NET machine. I told him how excited I was about his work on an ASP.NET Task Scheduler and as a result have been made an honorary participant in The Abidar Project (Keyvan comes up with the best names.) You'll find Abidar in its inception phase on CodePlex. So that it's clear, this is Keyvan's project and I am along for the ride.

As you might infer from my Services page, I'm working on a framework to extend and customize Open Source Community Applications. Creating background tasks would be an essential component of that framework, just as it is an important element in Community Server development.

Keyvan's energy inspired me to begin approaching an ASP.NET Task Scheduler for use in the real world. With the post of Keyvan's Task Scheduler, Part II I was able to take his code and within a few minutes have a functional background task running on Application_Start().

I've been studying Open Source development lately and one of the startup rules of an Open Source Project is to scour the net to see if what you want to do has already been done. While I found no ASP.NET Task Scheduler projects per se, I did find this excellent 2003 Angry Coder post by Michael Teper.

To take Keyvan's source to the next phase would require loading multiple tasks described in a database table or configuration file. Michael's post provided the ingredients for the next course. (I've been watching too much of the Food Network lately...)

Using Michael's logic, instead of starting a specific task in the Global.asax like so,

void Application_Start(object sender, EventArgs e)
{
someTask.StartTask();
}


we employee a SchedulerConfiguration class specifying the sleep interval (for now) and a list of tasks. Now we can load those tasks from some other source and pass them to a Scheduler class that executes the individual tasks in the Configuration file. The logic would be

SchedulerConfiguration config = new SchedulerConfiguration([sleepInterval]);
foreach (task from config file or other source)
{
string _typeString = "Some.Class, SomeNamespace";
Type _type = Type.GetType(_typeString);
ISchedulerTask task = Activator.CreateInstance(_type) as ISchedulerTask;
config.Tasks.Add(task);
}
Scheduler scheduler = new Scheduler(config);
System.Threading.ThreadStart _threadStart = new System.Threading.ThreadStart(scheduler.Start);
schedulerThread = new System.Threading.Thread(_threadStart);
schedulerThread.Start();


The Sleep Interval needs to be task-specific, of course, which is where Keyvan's source code comes in. We would also want to add the interval and other properties Keyvan listed in his code to a task base class - IsRunning, LastRunTime, and so on.

The two hours or so on a Sunday night spent on the above proves that an Open Source ASP.NET Task Scheduler is definitely doable. So as Keyvan said at the bottom of his Abidar announcement, Stay tuned!

Comments (7) | Post RSS RSS comment feed

Posted on 7/1/2008 4:23:23 PM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (7) -

7/3/2008 3:56:23 AM Permalink

2 words - Provider Model  Smile

Bill Bosacker United States |

7/3/2008 5:36:32 AM Permalink

Bill, you always like giving that "X words" type of advice, don't you. Smile Provider model, eh?  That would be part of this framework, for sure, but I'm not immediately seeing how this fits into the task scheduling function.  Definitely not opposed to it.  Thanks for watching!

Dave Burke United States |

7/3/2008 12:12:26 PM Permalink

The ASP.NET provider model is extremely extensive and would allow you to configure your task manager from the web.config.  And instead of using the global.asax, an HttpModule is a much better choice and is portable/reusable.  The HttpModule would control the creation and destruction of you scheduler provider.  Smile

Bill Bosacker United States |

7/3/2008 12:28:46 PM Permalink

Oh great, now I have to study up on the HttpModule approach.  Seriously, I'll definitely look into it. It's not the way it's done in CS though... Smile

Dave Burke United States |

7/3/2008 1:12:17 PM Permalink

I certainly hope the happy face is for the last statement.  ;)

Bill Bosacker United States |

7/3/2008 1:49:19 PM Permalink

Hey, man.  You know I think you're the Cat's Meow and take what you say seriously!  And no, CS doesn't use a provider or HttpModules with its task scheduling system.  

Dave Burke United States |

7/3/2008 2:48:00 PM Permalink

Smile
The whole provider system is just awesome in what you can do with it as it modular and basically a plug-n-play system for applications.  I spent the entire past year writing them and custom HttpModules for the security system that I was working on.  CS makes use of a mock provider system with it's CSModules, which should really just be plug-ins for a provider.  I created a plug-in system for my Membership Provider, and then created an RSA plug-in.  Works pretty slick.

Bill Bosacker United States |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke