Skip to content

Commit

Permalink
Handle a case when the duration to the next task execution is greater…
Browse files Browse the repository at this point in the history
… than int.MaxValue. Fixes #7
  • Loading branch information
jgeurts committed Dec 12, 2012
1 parent 4cd9083 commit fb97d35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 3 additions & 7 deletions ConsoleTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ public class MyRegistry : Registry
{
public MyRegistry()
{
DefaultAllTasksAsNonReentrant();

Schedule(() =>
{
Console.WriteLine("Before sleep - " + DateTime.Now);
Console.WriteLine("Running Tasks: " + TaskManager.RunningSchedules.Count);
Thread.Sleep(4000);
Console.WriteLine("After sleep - " + DateTime.Now);
}).WithName("Sleepy Task").NonReentrant().ToRunNow().AndEvery(1).Seconds();

Schedule(() =>
{
Console.WriteLine("Before exception");
throw new Exception("Test throwing an exception, to make sure UnobservedTaskException is raised properly");
}).WithName("Exception Task").NonReentrant().ToRunNow().AndEvery(1).Seconds();
}).WithName("Sleepy Task").ToRunEvery(1).Months().On(10).At(5,0);
}
}

Expand Down
3 changes: 3 additions & 0 deletions FluentScheduler/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ private static void Schedule()
Schedule();
return;
}
// If the interval is greater than what the _timer supports, just go for int.MaxValue. A new interval will be calculated the next time the timer runs.
if (timerInterval > int.MaxValue)
timerInterval = int.MaxValue;

_timer.Interval = timerInterval;
_timer.Start();
Expand Down

0 comments on commit fb97d35

Please sign in to comment.