/// <summary>
 /// Create a timer with custamizable ticks interval and default timeout of TimedCallback.
 /// </summary>
 /// <param name="interval"></param>
 /// <param name="defaultTimeout"></param>
 /// <param name="policy"></param>
 public HashedWheelTimer(TimeSpan interval, TimeSpan defaultTimeout, SleepPolicy policy = SleepPolicy.Default)
 {
     TicksInterval  = NanoTime.FromMilliseconds(interval.TotalMilliseconds);
     DefaultTimeout = NanoTime.FromMilliseconds(defaultTimeout.TotalMilliseconds);
     ticked         = 0;
     SetSleep(policy);
     InitializeSlots();
     workerThread = new Thread(WorkLoop);
     time.Start();
     workerThread.Start();
 }
        private void SetSleep(SleepPolicy policy)
        {
            switch (policy)
            {
            case SleepPolicy.Native:
            case SleepPolicy.Default:
                Sleep = SleepMethods.NativeSleep;
                break;

            case SleepPolicy.Precise:
                Sleep = SleepMethods.PreciseSleep;
                break;
            }
        }
 /// <summary>
 /// Create a timer with specified tick interval and sleep policy.
 /// </summary>
 /// <param name="interval">ticks interval</param>
 /// <param name="policy">Sleep policy</param>
 public HashedWheelTimer(TimeSpan interval, SleepPolicy policy = SleepPolicy.Default)
     : this(policy)
 {
     TicksInterval = NanoTime.FromMilliseconds(interval.TotalMilliseconds);
 }
 /// <summary>
 /// Create a timer with default tick interval (50ms).
 /// </summary>
 /// <param name="policy">Sleep precision.
 /// By default Native will be used, which invokes Thread.Sleep. </param>
 public HashedWheelTimer(SleepPolicy policy = SleepPolicy.Default)
 {
     SetSleep(policy);
     DefaultInitialize();
 }