Exemple #1
0
 void Timer_Elapsed(object state)
 {
     if (!_enabled)
     {
         return;
     }
     lock (_lock) {
         if (Elapsed100Ms != null)
         {
             SafeInvoke(Elapsed100Ms.GetInvocationList());
         }
         var utcNow  = _timeService.UtcNow;
         var seconds = (int)utcNow.TimeOfDay.TotalSeconds;
         if (seconds == _lastSeconds)
         {
             return;
         }
         _lastSeconds = seconds;
         if (Elapsed1Second != null)
         {
             SafeInvoke(Elapsed1Second.GetInvocationList());
         }
         if (seconds % 10 == 0 && Elapsed10Seconds != null)
         {
             SafeInvoke(Elapsed10Seconds.GetInvocationList());
         }
         if (seconds % 60 == 0 && Elapsed1Minute != null)
         {
             SafeInvoke(Elapsed1Minute.GetInvocationList());
         }
         var oneMin = 60;
         if (seconds % (5 * oneMin) == 0 && Elapsed5Minutes != null)
         {
             SafeInvoke(Elapsed5Minutes.GetInvocationList());
         }
         if (seconds % (15 * oneMin) == 0 && Elapsed15Minutes != null)
         {
             SafeInvoke(Elapsed15Minutes.GetInvocationList());
         }
         if (seconds % (30 * oneMin) == 0 && Elapsed30Minutes != null)
         {
             SafeInvoke(Elapsed30Minutes.GetInvocationList());
         }
         if (seconds % (60 * oneMin) == 0 && Elapsed60Minutes != null)
         {
             SafeInvoke(Elapsed60Minutes.GetInvocationList());
         }
         if (seconds % (60 * 6 * oneMin) == 0 && Elapsed6Hours != null)
         {
             SafeInvoke(Elapsed6Hours.GetInvocationList());
         }
         if (seconds % (60 * 24 * oneMin) == 0 && Elapsed24Hours != null)
         {
             SafeInvoke(Elapsed24Hours.GetInvocationList());
         }
     }
 }
Exemple #2
0
 void Timer_Elapsed(object state)
 {
     if (!_enabled)
     {
         return;
     }
     lock (_lock) {
         if (Elapsed100Ms != null)
         {
             SafeInvoke(Elapsed100Ms.GetInvocationList());
         }
         var utcNow    = _timeService.UtcNow;
         var tickCount = (long)utcNow.TimeOfDay.TotalMilliseconds / 100;
         if (tickCount == _lastTickCount)
         {
             return;
         }
         _lastTickCount = tickCount;
         if (Elapsed500Ms != null && (tickCount % 5 == 0))
         {
             SafeInvoke(Elapsed500Ms.GetInvocationList());
         }
         // Now all in 1 second intervals
         var seconds = tickCount / 10;
         if (Elapsed1Second != null)
         {
             SafeInvoke(Elapsed1Second.GetInvocationList());
         }
         if (seconds % 10 == 0 && Elapsed10Seconds != null)
         {
             SafeInvoke(Elapsed10Seconds.GetInvocationList());
         }
         if (seconds % 60 == 0 && Elapsed1Minute != null)
         {
             SafeInvoke(Elapsed1Minute.GetInvocationList());
         }
         var oneMin = 60;
         if (seconds % (5 * oneMin) == 0 && Elapsed5Minutes != null)
         {
             SafeInvoke(Elapsed5Minutes.GetInvocationList());
         }
         if (seconds % (15 * oneMin) == 0 && Elapsed15Minutes != null)
         {
             SafeInvoke(Elapsed15Minutes.GetInvocationList());
         }
         if (seconds % (30 * oneMin) == 0 && Elapsed30Minutes != null)
         {
             SafeInvoke(Elapsed30Minutes.GetInvocationList());
         }
         if (seconds % (60 * oneMin) == 0 && Elapsed60Minutes != null)
         {
             SafeInvoke(Elapsed60Minutes.GetInvocationList());
         }
         if (seconds % (60 * 6 * oneMin) == 0 && Elapsed6Hours != null)
         {
             SafeInvoke(Elapsed6Hours.GetInvocationList());
         }
         if (seconds % (60 * 24 * oneMin) == 0 && Elapsed24Hours != null)
         {
             SafeInvoke(Elapsed24Hours.GetInvocationList());
         }
     }
 }