From 6b8362d57d30022b16affd9111ab9651c11f1a41 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Tue, 9 Jun 2009 19:41:38 +0000 Subject: [PATCH] Fixed a nasty bug that would make the scheduler queue notifications using their delay time as absolute notification time, causing negative numbers to be passed to WaitOne(); updated unit test to expose this problem if it happens git-svn-id: file:///srv/devel/repo-conversion/nusu@146 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/Scheduling/Scheduler.Test.cs | 1 + Source/Scheduling/Scheduler.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Scheduling/Scheduler.Test.cs b/Source/Scheduling/Scheduler.Test.cs index 1cdf595..e84c967 100644 --- a/Source/Scheduling/Scheduler.Test.cs +++ b/Source/Scheduling/Scheduler.Test.cs @@ -47,6 +47,7 @@ namespace Nuclex.Support.Scheduling { /// Start time in UTC format public MockTimeSource(DateTime utcStartTime) { this.currentTime = utcStartTime; + this.currentTicks = 1000000000; } /// Waits for an AutoResetEvent to become signalled diff --git a/Source/Scheduling/Scheduler.cs b/Source/Scheduling/Scheduler.cs index be4d038..7726b5b 100644 --- a/Source/Scheduling/Scheduler.cs +++ b/Source/Scheduling/Scheduler.cs @@ -128,10 +128,10 @@ namespace Nuclex.Support.Scheduling { } } - #endregion // class NotificationComparer - } + #endregion // class NotificationComparer + /// Initializes a new scheduler using the default time source public Scheduler() : this(DefaultTimeSource) { } @@ -235,7 +235,7 @@ namespace Nuclex.Support.Scheduling { return scheduleNotification( new Notification( 0, - delay.Ticks, + this.timeSource.Ticks + delay.Ticks, DateTime.MinValue, callback ) @@ -256,7 +256,7 @@ namespace Nuclex.Support.Scheduling { return scheduleNotification( new Notification( 0, - (long)delayMilliseconds * TicksPerMillisecond, + this.timeSource.Ticks + ((long)delayMilliseconds * TicksPerMillisecond), DateTime.MinValue, callback ) @@ -276,7 +276,7 @@ namespace Nuclex.Support.Scheduling { return scheduleNotification( new Notification( interval.Ticks, - delay.Ticks, + this.timeSource.Ticks + delay.Ticks, DateTime.MinValue, callback ) @@ -302,7 +302,7 @@ namespace Nuclex.Support.Scheduling { return scheduleNotification( new Notification( (long)intervalMilliseconds * TicksPerMillisecond, - (long)delayMilliseconds * TicksPerMillisecond, + this.timeSource.Ticks + ((long)delayMilliseconds * TicksPerMillisecond), DateTime.MinValue, callback )