Esempio n. 1
0
        public long timeout_us(long us, Action handler)
        {
            Debug.Assert(_strand.running_in_this_thread() && null == _handler && null != handler, "不正确的 timeout_us 调用!");
            _isInterval = false;
            _handler    = handler;
            _strand.hold_work();
            long nowus = _utcMode ? utc_tick.get_tick_us() : system_tick.get_tick_us();

            begin_timer(nowus, us > 0 ? nowus + us : nowus, us > 0 ? us : 0);
            return(nowus);
        }
Esempio n. 2
0
 public long timeout_us(long us, Action handler)
 {
     Debug.Assert(_strand.running_in_this_thread() && null == _handler && null != handler, "不正确的 timeout_us 调用!");
     _isInterval = false;
     _handler    = handler;
     _strand.hold_work();
     _beginTick = _utcMode ? utc_tick.get_tick_us() : system_tick.get_tick_us();
     if (0 < us)
     {
         begin_timer(_beginTick + us, us);
     }
     else
     {
         tick_timer(_beginTick);
     }
     return(_beginTick);
 }
Esempio n. 3
0
 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);
 }