private void ProcessWork(TimeSpan now) { try { _inProcessingWork = true; while (_works.Any()) { var work = _works[0]; if (work.Time > now) { ActionScheduled?.Invoke(work.Time - now, ProcessWork); return; } _works.RemoveAt(0); var entity = _zone.GetEntity(work.EntityId); if (entity != null) { work.Action(entity, work.TimerId); if (work.Interval > TimeSpan.Zero) { work.Time = now + work.Interval; QueueWork(work); } } } } finally { _inProcessingWork = false; } }