This past weekend I published a small open source project at CodePlex, Task Scheduler Engine. It is a simple cron-like scheduling API with a clean fluent interface (also supports XML config, if you prefer typing out assembly qualified names). Use it when you need a simple, in-memory scheduler and when you need tasks to execute at a specific second (in other words, if you start doing math to compute the duration of your timer so that it fires at a specific time, use this instead). If you have multiple services load balanced to execute tasks, this isn’t for you.
Here’s all that’s required to schedule a task (write console output) to execute every ten seconds:
var s = new Schedule() .AtSeconds(0, 10, 20, 30, 40, 50) .WithLocalTime() .Execute<ConsoleWriteTask>();SchedulerRuntime.Start(s);
Creating your own tasks is just as easy—implement ITask, which has an Initialize method and a Handle method that is called at the scheduled time.
It compiles to an 18KB assembly, has no external (non-framework) dependencies, and is just over 250 lines of code. Add clean, simple scheduling to your .NET application.
No comments:
Post a Comment