I'm spec'ing out a API for a task scheduler and I would be thankful for your thoughts. This is what I've got so far:

public void Configure(Context ctx) {
    // Single tasks
    ctx.Run(() => Tasks.First()).Every.Midnight;
    ctx.Run(() => Tasks.Second()).Every.Day(8,0));

    // Multiple tasks
    ctx.Run(() => {

   // Triggers:

The run method accepts an Action parameter.

Obviously, I need to support custom triggers to allow users to configure it exactly as they want. It could be done by implementing an interface like:

interface ITask {
    bool ShouldRun(DateTime currentDate);
  • 1
    \$\begingroup\$ I wouldn't bother with all your various every overloads, if you want fluent style replace the everys with a single method .AndReoccur(int numberOfTimes, Timespan interval) also I'm pretty sure this site is supposed to be for compilable functioning code, maybe this fits on stackoverflow better? \$\endgroup\$ Aug 12, 2011 at 1:59

2 Answers 2


Instead of rolling your own API for repetitions, I'd adopt the terminology and semantics of RFC 5545 RRULEs which is widely used within Calendaring applications

Section thoroughly documents the syntax and behavior of RRULEs (Recurrence rules). They look like


which means

Weekly on Tuesday and Thursday for five weeks:

so you could implement these semantics (or find an existing RFC 5545 library that does it) and your API might look very similar to the RRULE syntax:

ctx.Run(...).Freq(WEEKLY).Count(10).ByDay(TU, TH)

I'd like to be able to use a non-functional approach to running the api. Perhaps I'm a new developer and don't understand lambdas. Give me the option to go.

ctx.Run(//Task, or List of tasks,  //How often, //Time to start, //Possible skip conditions - maybe skip weekends);

//Utilize enums that they can use
ctx.Run(Task.First(), Frequency.Daily, Time.Midnight);

//or pass a list of tasks perhaps
List<Task> tasks;
ctx.Run(tasks, Frequency.Hourly, Time.Custom(hour, min, sec), Time.Weekends);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.