public void AddTimer(TimerEvent timerEvent) { UpdatePeriods(timerEvent.Period); int min = 999999999; uint startIndex = 0; for (var i = 0; i < _slotsCount; i++) { if (min > _pSlots[i].Count) { startIndex = (uint)i; min = _pSlots[i].Count; } } while (!_pSlots[(int) (startIndex % _slotsCount)].ContainsKey(timerEvent.Id)) { _pSlots[(int) (startIndex % _slotsCount)][timerEvent.Id] = timerEvent; startIndex += timerEvent.Period; } }
public static bool EnableTimer(this IOHandler ioHandler, uint seconds) { var timerEvent = new TimerEvent {Id = ioHandler.Id,Period = seconds}; TimersManager.AddTimer(timerEvent); return true; }
public static void ProcessTimer(TimerEvent timerEvent) { if (!ActiveIoHandler.ContainsKey(timerEvent.Id)) return; if (!ActiveIoHandler[timerEvent.Id].OnEvent(null)) { EnqueueForDelete(ActiveIoHandler[timerEvent.Id]); } }