Pattern: Task Scheduler

Topics: Samples and Patterns
Jan 20, 2007 at 6:21 PM

/// <summary>
/// It is hard to get easier then this for a simple task scheduler.
/// Can get as complex as needed.
/// </summary>
private static void BasicTaskScheduler()
    Port<string> p = new Port<string>();
    Selector.SelectOne(true, p,
        delegate(string cmd)
            Console.WriteLine("Ran [{0}] at {1}", cmd, DateTime.Now.ToString());
    // Schedule tasks in future. If you want to start at a DateTime, just calc timespan from future datetime.
    p.Push("dir", TimeSpan.FromSeconds(1));
    p.Push("backup", TimeSpan.FromSeconds(2));