Exemplo n.º 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());
         }
     }
 }
Exemplo n.º 2
0
 //ITimerServiceControl
 public void FireAll()
 {
     lock (_lock) {
         try {
             Elapsed100Ms?.Invoke(this, EventArgs.Empty);
             Elapsed1Second?.Invoke(this, EventArgs.Empty);
             Elapsed10Seconds?.Invoke(this, EventArgs.Empty);
             Elapsed1Minute?.Invoke(this, EventArgs.Empty);
             Elapsed5Minutes?.Invoke(this, EventArgs.Empty);
             Elapsed15Minutes?.Invoke(this, EventArgs.Empty);
             Elapsed15Minutes?.Invoke(this, EventArgs.Empty);
             Elapsed30Minutes?.Invoke(this, EventArgs.Empty);
             Elapsed60Minutes?.Invoke(this, EventArgs.Empty);
             Elapsed6Hours?.Invoke(this, EventArgs.Empty);
             Elapsed24Hours?.Invoke(this, EventArgs.Empty);
         } catch (Exception ex) {
             if (_errorLog != null)
             {
                 _errorLog.LogError(ex);
             }
         }
     }
 }
Exemplo n.º 3
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());
         }
     }
 }