private void timer_handler() { _onTopCall = true; if (_isInterval) { int lastTc = _timerCount; functional.catch_invoke(_handler); if (lastTc == _timerCount) { begin_timer(_beginTick, _timerHandle.absus += _timerHandle.period, _timerHandle.period); } } else { Action handler = _handler; _handler = null; _strand.release_work(); functional.catch_invoke(handler); } _onTopCall = false; }
private void begin_timer(long tick, long dueTime, int period) { if (null == _timer) { _strand.hold_work(); } _timer = new Timer(delegate(object state) { _strand.post(delegate() { if ((int)state == _timerCount) { _beginTick = 0; _onTopCall = true; if (_isInterval) { functional.func handler = _handler; handler(); if ((int)state == _timerCount) { tick += period; dueTime = tick - system_tick.get_tick_ms(); begin_timer(tick, dueTime > 0 ? dueTime : 0, period); } } else { functional.func handler = _handler; _handler = null; _timer = null; _strand.release_work(); handler(); } _onTopCall = false; } }); }, _timerCount, dueTime, 0); }