示例#1
0
 private void SignalTimer(DispatcherQueue.TimerContext tc)
 {
     try
     {
         Dispatcher.SetCurrentThreadCausalities(tc.CausalityContext);
         tc.TimerPort.Post(DateTime.Now);
         Dispatcher.ClearCausalities();
     }
     catch (Exception exception)
     {
         Dispatcher.LogError("DispatcherQueue:TimerHandler", exception);
     }
 }
示例#2
0
        public virtual void EnqueueTimer(TimeSpan timeSpan, Port <DateTime> timerPort)
        {
            if (_dispatcher == null || (_dispatcher.Options & DispatcherOptions.UseHighAccuracyTimerLogic) == DispatcherOptions.None)
            {
                EnqueueTimerUsingClrSystemTimers(timeSpan, timerPort);
                return;
            }
            CausalityThreadContext causalityContext = Dispatcher.CloneCausalitiesFromCurrentThread();

            timeSpan = TimeSpan.FromSeconds(timeSpan.TotalSeconds * _timescale);
            DateTime dateTime = DateTime.UtcNow + timeSpan;

            DispatcherQueue.TimerContext item = new DispatcherQueue.TimerContext(timerPort, causalityContext, dateTime);
            bool flag = false;

            lock (_timerTable)
            {
                if (dateTime < _nextTimerExpiration)
                {
                    _nextTimerExpiration = dateTime;
                    flag = true;
                }
                if (_timerTable.ContainsKey(dateTime.Ticks))
                {
                    _timerTable[dateTime.Ticks].Add(item);
                }
                else
                {
                    List <DispatcherQueue.TimerContext> list = new List <DispatcherQueue.TimerContext>(1);
                    list.Add(item);
                    _timerTable[dateTime.Ticks] = list;
                }
            }
            if (flag)
            {
                Enqueue(new Task(delegate
                {
                }));
            }
        }