diff --git a/Server/Timer.cs b/Server/Timer.cs index aa5adb83a..17061b508 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -41,6 +41,7 @@ namespace Server public delegate void TimerCallback(); public delegate void TimerStateCallback( object state ); + public delegate void TimerStateCallback( T state ); public class TimerProfile { @@ -614,6 +615,31 @@ namespace Server return t; } + + public static Timer DelayCall( TimeSpan delay, TimerStateCallback callback, T state ) + { + return DelayCall( delay, TimeSpan.Zero, 1, callback, state ); + } + + public static Timer DelayCall( TimeSpan delay, TimeSpan interval, TimerStateCallback callback, T state ) + { + return DelayCall( delay, interval, 0, callback, state ); + } + + public static Timer DelayCall( TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, T state ) + { + Timer t = new DelayStateCallTimer( delay, interval, count, callback, state ); + + if( count == 1 ) + t.Priority = ComputePriority( delay ); + else + t.Priority = ComputePriority( interval ); + + t.Start(); + + return t; + } + private class DelayCallTimer : Timer { private TimerCallback m_Callback; @@ -669,6 +695,36 @@ namespace Server } } + private class DelayStateCallTimer : Timer + { + private TimerStateCallback m_Callback; + private T m_State; + + public TimerStateCallback Callback { get { return m_Callback; } } + + public override bool DefRegCreation { get { return false; } } + + public DelayStateCallTimer( TimeSpan delay, TimeSpan interval, int count, TimerStateCallback callback, T state ) + : base( delay, interval, count ) + { + m_Callback = callback; + m_State = state; + + RegCreation(); + } + + protected override void OnTick() + { + if( m_Callback != null ) + m_Callback( m_State ); + } + + public override string ToString() + { + return String.Format( "DelayStateCall[{0}]", FormatDelegate( m_Callback ) ); + } + } + public void Start() { if ( !m_Running )