/// <summary> /// Detaches timer consumer. /// </summary> /// <param name="iTimerConsumer">Timer consumer to attach.</param> public static void Detach(ITimerConsumer iTimerConsumer) { lock(_clients) { _clients.Remove(new WeakReference(iTimerConsumer)); } }
/// <summary> /// Attaches timer consumer. /// </summary> /// <param name="iTimerConsumer">Timer consumer to attach.</param> public static void Attach(ITimerConsumer iTimerConsumer) { lock(_clients) { _clients.Add(new WeakReference(iTimerConsumer)); } }
/// <summary> /// Attaches timer consumer. /// </summary> /// <param name="iTimerConsumer">Timer consumer to attach.</param> public static void Attach(ITimerConsumer iTimerConsumer) { lock (_clients) { _clients.Add(new WeakReference(iTimerConsumer)); } }
/// <summary> /// Detaches timer consumer. /// </summary> /// <param name="iTimerConsumer">Timer consumer to attach.</param> public static void Detach(ITimerConsumer iTimerConsumer) { lock (_clients) { _clients.Remove(new WeakReference(iTimerConsumer)); } }
/// <summary> /// Is executed every 10 seconds. /// </summary> /// <param name="state">Useless parameter.</param> public static void TimerCallback(object state) { lock (_clients) { for (int i = 0; i < _clients.Count;) { ITimerConsumer iTimerConsumer = null; WeakReference weakReference = _clients[i] as WeakReference; if (weakReference != null) { iTimerConsumer = weakReference.Target as ITimerConsumer; } if (iTimerConsumer == null) { _clients.RemoveAt(i); continue; } // safe call try { iTimerConsumer.TimerCallback(); } catch (Exception) { } i++; } } }