Added an interface for the scheduler service (this might be once candidate for replacement by different implementations); added a new helper class for the StringBuilder that allows garbage-free appending of integers and floats; added unit tests for most of the code
git-svn-id: file:///srv/devel/repo-conversion/nusu@188 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
66f0ae9b34
commit
237fb57fc8
8 changed files with 468 additions and 3 deletions
101
Source/Scheduling/ISchedulerService.cs
Normal file
101
Source/Scheduling/ISchedulerService.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
#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;
|
||||
|
||||
namespace Nuclex.Support.Scheduling {
|
||||
|
||||
/// <summary>Service that allows the scheduled invocation of tasks</summary>
|
||||
public interface ISchedulerService {
|
||||
|
||||
/// <summary>Schedules a notification at the specified absolute time</summary>
|
||||
/// <param name="notificationTime">
|
||||
/// Absolute time at which the notification will occur
|
||||
/// </param>
|
||||
/// <param name="callback">
|
||||
/// Callback that will be invoked when the notification is due
|
||||
/// </param>
|
||||
/// <returns>A handle that can be used to cancel the notification</returns>
|
||||
/// <remarks>
|
||||
/// The notification is scheduled for the indicated absolute time. If the system
|
||||
/// enters/leaves daylight saving time or the date/time is changed (for example
|
||||
/// when the system synchronizes with an NTP server), this will affect
|
||||
/// the notification. So if you need to be notified after a fixed time, use
|
||||
/// the NotifyIn() method instead.
|
||||
/// </remarks>
|
||||
object NotifyAt(DateTime notificationTime, WaitCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Schedules a recurring notification after the specified amount of milliseconds
|
||||
/// </summary>
|
||||
/// <param name="delayMilliseconds">
|
||||
/// Milliseconds after which the first notification will occur
|
||||
/// </param>
|
||||
/// <param name="intervalMilliseconds">
|
||||
/// Interval in milliseconds at which the notification will be repeated
|
||||
/// </param>
|
||||
/// <param name="callback">
|
||||
/// 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);
|
||||
|
||||
/// <summary>
|
||||
/// Schedules a recurring notification after the specified time span
|
||||
/// </summary>
|
||||
/// <param name="delay">Delay after which the first notification will occur</param>
|
||||
/// <param name="interval">Interval at which the notification will be repeated</param>
|
||||
/// <param name="callback">
|
||||
/// 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(TimeSpan delay, TimeSpan interval, WaitCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Schedules a notification after the specified amount of milliseconds
|
||||
/// </summary>
|
||||
/// <param name="delayMilliseconds">
|
||||
/// Number of milliseconds after which the notification will occur
|
||||
/// </param>
|
||||
/// <param name="callback">
|
||||
/// Callback that will be invoked when the notification is due
|
||||
/// </param>
|
||||
/// <returns>A handle that can be used to cancel the notification</returns>
|
||||
object NotifyIn(int delayMilliseconds, WaitCallback callback);
|
||||
|
||||
/// <summary>Schedules a notification after the specified time span</summary>
|
||||
/// <param name="delay">Delay after which the notification will occur</param>
|
||||
/// <param name="callback">
|
||||
/// Callback that will be invoked when the notification is due
|
||||
/// </param>
|
||||
/// <returns>A handle that can be used to cancel the notification</returns>
|
||||
object NotifyIn(TimeSpan delay, WaitCallback callback);
|
||||
|
||||
/// <summary>Cancels a scheduled notification</summary>
|
||||
/// <param name="notificationHandle">
|
||||
/// Handle of the notification that will be cancelled
|
||||
/// </param>
|
||||
void Cancel(object notificationHandle);
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Scheduling
|
|
@ -28,7 +28,7 @@ using Nuclex.Support.Collections;
|
|||
namespace Nuclex.Support.Scheduling {
|
||||
|
||||
/// <summary>Schedules actions for execution at a future point in time</summary>
|
||||
public class Scheduler : IDisposable {
|
||||
public class Scheduler : ISchedulerService, IDisposable {
|
||||
|
||||
/// <summary>One tick is 100 ns, meaning 10000 ticks equal 1 ms</summary>
|
||||
private const long TicksPerMillisecond = 10000;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue