Scheduler is a simple C# implementation of a scheduler that supports recurring events and unit testing with "Time travel".
nuget install SharpScheduler # Install Scheduler
IScheduler scheduler = new Scheduler();
// In two seconds run SendNotification
scheduler.Schedule(TimeSpan.FromSeconds(2), () => SendNotification());
// In two seconds run SendNotification
scheduler.Schedule(TimeSpan.FromSeconds(2), _ => SendNotification(), exception =>
{
// Handle Exception here
});
// Every thirty ms run UpdateStats
scheduler.SchedulePeriodic(TimeSpan.FromMilliseconds(30), () => UpdateStats());
var scheduler = new TestScheduler();
var x = 0;
scheduler.Schedule(TimeSpan.FromSeconds(2), () => x++);
scheduler.AdvanceBy(TimeSpan.FromSeconds(2));
Assert.Equal(1, x);
var scheduler = new TestScheduler();
var y = 0;
scheduler.SchedulePeriodic(TimeSpan.FromSeconds(1), _ => y++);
scheduler.AdvanceBy(TimeSpan.FromSeconds(2));
Assert.Equal(3, y);