Split Scheduler class into two files, one containing only the static time source management code (which I might decide to put somewhere else after all); added an option for users of the scheduler to query the scheduler's time source; fixed typo

git-svn-id: file:///srv/devel/repo-conversion/nusu@191 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2010-03-03 20:47:45 +00:00
parent 35a4da16fc
commit 2b94c316f6
6 changed files with 103 additions and 47 deletions

View File

@ -152,6 +152,9 @@
<Compile Include="Source\Scheduling\Scheduler.Test.cs">
<DependentUpon>Scheduler.cs</DependentUpon>
</Compile>
<Compile Include="Source\Scheduling\Scheduler.TimeSource.cs">
<DependentUpon>Scheduler.cs</DependentUpon>
</Compile>
<Compile Include="Source\Scheduling\WindowsTimeSource.cs" />
<Compile Include="Source\Scheduling\WindowsTimeSource.Test.cs">
<DependentUpon>WindowsTimeSource.cs</DependentUpon>

View File

@ -138,6 +138,9 @@
<Compile Include="Source\Scheduling\Scheduler.Test.cs">
<DependentUpon>Scheduler.cs</DependentUpon>
</Compile>
<Compile Include="Source\Scheduling\Scheduler.TimeSource.cs">
<DependentUpon>Scheduler.cs</DependentUpon>
</Compile>
<Compile Include="Source\Scheduling\WindowsTimeSource.cs" />
<Compile Include="Source\Scheduling\WindowsTimeSource.Test.cs">
<DependentUpon>WindowsTimeSource.cs</DependentUpon>

View File

@ -115,7 +115,7 @@ namespace Nuclex.Support {
BindingFlags.Public | BindingFlags.Static
);
// Create an array to hold the enumeration value and copy them over from
// Create an array to hold the enumeration values and copy them over from
// the fields we just retrieved
EnumType[] values = new EnumType[fieldInfos.Length];
for(int index = 0; index < fieldInfos.Length; ++index) {

View File

@ -24,9 +24,17 @@ using System.Threading;
namespace Nuclex.Support.Scheduling {
#if SCHEDULER_USE_CUSTOM_CALLBACK
/// <summary>Signature for a timed callback from the scheduler service</summary>
public delegate void SchedulerCallback();
#endif // SCHEDULER_USE_CUSTOM_CALLBACK
/// <summary>Service that allows the scheduled invocation of tasks</summary>
public interface ISchedulerService {
/// <summary>Time source being used by the scheduler</summary>
ITimeSource TimeSource { get; }
/// <summary>Schedules a notification at the specified absolute time</summary>
/// <param name="notificationTime">
/// Absolute time at which the notification will occur
@ -57,7 +65,9 @@ namespace Nuclex.Support.Scheduling {
/// Callback that will be invoked when the notification is due
/// </param>
/// <returns>A handle that can be used to cancel the notification</returns>
object NotifyEach(int delayMilliseconds, int intervalMilliseconds, WaitCallback callback);
object NotifyEach(
int delayMilliseconds, int intervalMilliseconds, WaitCallback callback
);
/// <summary>
/// Schedules a recurring notification after the specified time span

View File

@ -0,0 +1,79 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using Nuclex.Support.Collections;
namespace Nuclex.Support.Scheduling {
/// <summary>Schedules actions for execution at a future point in time</summary>
partial class Scheduler {
#region class TimeSourceSingleton
/// <summary>
/// Manages the singleton instance of the scheduler's default time source
/// </summary>
private class TimeSourceSingleton {
/// <summary>
/// Explicit static constructor to guarantee the singleton is initialized only
/// when a static member of this class is accessed.
/// </summary>
static TimeSourceSingleton() { } // Do not remove!
/// <summary>The singleton instance of the default time source</summary>
internal static readonly ITimeSource Instance = Scheduler.CreateDefaultTimeSource();
}
#endregion // class TimeSourceSingleton
/// <summary>Returns the default time source for the scheduler</summary>
public static ITimeSource DefaultTimeSource {
get { return TimeSourceSingleton.Instance; }
}
/// <summary>Creates a new default time source for the scheduler</summary>
/// <param name="useWindowsTimeSource">
/// Whether the specialized windows time source should be used
/// </param>
/// <returns>The newly created time source</returns>
internal static ITimeSource CreateTimeSource(bool useWindowsTimeSource) {
if(useWindowsTimeSource) {
return new WindowsTimeSource();
} else {
return new GenericTimeSource();
}
}
/// <summary>Creates a new default time source for the scheduler</summary>
/// <returns>The newly created time source</returns>
internal static ITimeSource CreateDefaultTimeSource() {
return CreateTimeSource(WindowsTimeSource.Available);
}
}
} // namespace Nuclex.Support.Scheduling

View File

@ -28,31 +28,11 @@ using Nuclex.Support.Collections;
namespace Nuclex.Support.Scheduling {
/// <summary>Schedules actions for execution at a future point in time</summary>
public class Scheduler : ISchedulerService, IDisposable {
public partial class Scheduler : ISchedulerService, IDisposable {
/// <summary>One tick is 100 ns, meaning 10000 ticks equal 1 ms</summary>
private const long TicksPerMillisecond = 10000;
#region class TimeSourceSingleton
/// <summary>
/// Manages the singleton instance of the scheduler's default time source
/// </summary>
private class TimeSourceSingleton {
/// <summary>
/// Explicit static constructor to guarantee the singleton is initialized only
/// when a static member of this class is accessed.
/// </summary>
static TimeSourceSingleton() { } // Do not remove!
/// <summary>The singleton instance of the default time source</summary>
internal static readonly ITimeSource Instance = Scheduler.CreateDefaultTimeSource();
}
#endregion // class TimeSourceSingleton
#region class Notification
/// <summary>Scheduled notification</summary>
@ -187,6 +167,11 @@ namespace Nuclex.Support.Scheduling {
}
}
/// <summary>Time source being used by the scheduler</summary>
public ITimeSource TimeSource {
get { return this.timeSource; }
}
/// <summary>Schedules a notification at the specified absolute time</summary>
/// <param name="notificationTime">
/// Absolute time at which the notification will occur
@ -320,30 +305,6 @@ namespace Nuclex.Support.Scheduling {
}
}
/// <summary>Returns the default time source for the scheduler</summary>
public static ITimeSource DefaultTimeSource {
get { return TimeSourceSingleton.Instance; }
}
/// <summary>Creates a new default time source for the scheduler</summary>
/// <param name="useWindowsTimeSource">
/// Whether the specialized windows time source should be used
/// </param>
/// <returns>The newly created time source</returns>
internal static ITimeSource CreateTimeSource(bool useWindowsTimeSource) {
if(useWindowsTimeSource) {
return new WindowsTimeSource();
} else {
return new GenericTimeSource();
}
}
/// <summary>Creates a new default time source for the scheduler</summary>
/// <returns>The newly created time source</returns>
internal static ITimeSource CreateDefaultTimeSource() {
return CreateTimeSource(WindowsTimeSource.Available);
}
/// <summary>Called when the system date/time have been adjusted</summary>
/// <param name="sender">Time source which detected the adjustment</param>
/// <param name="arguments">Not used</param>