private void ClrSystemTimerHandler(object state) { DispatcherQueue.ClrSystemTimerContext clrSystemTimerContext = (DispatcherQueue.ClrSystemTimerContext)state; try { lock (_clrSystemTimerTable) { _clrSystemTimerTable.Remove(clrSystemTimerContext.Id); } clrSystemTimerContext.Timer.Dispose(); Dispatcher.SetCurrentThreadCausalities(clrSystemTimerContext.CausalityContext); clrSystemTimerContext.TimerPort.Post(DateTime.Now); } catch (Exception exception) { Dispatcher.LogError("DispatcherQueue:TimerHandler", exception); } }
protected virtual Timer EnqueueTimerUsingClrSystemTimers(TimeSpan timeSpan, Port <DateTime> timerPort) { CausalityThreadContext causalityContext = Dispatcher.CloneCausalitiesFromCurrentThread(); if (timeSpan.TotalMilliseconds <= 5.0 && timeSpan.Milliseconds >= 0) { timerPort.Post(DateTime.Now); return(null); } timeSpan = TimeSpan.FromSeconds(timeSpan.TotalSeconds * _timescale); DispatcherQueue.ClrSystemTimerContext clrSystemTimerContext = new DispatcherQueue.ClrSystemTimerContext(timerPort, causalityContext); Timer timer = new Timer(new TimerCallback(ClrSystemTimerHandler), clrSystemTimerContext, -1, -1); clrSystemTimerContext.Timer = timer; lock (_clrSystemTimerTable) { _clrSystemTimerTable.Add(clrSystemTimerContext.Id, timer); } timer.Change(timeSpan, TimeSpan.FromMilliseconds(-1.0)); return(timer); }