Example #1
0
        /// <summary>
        /// Moves the clock forward to the current time and updates the state of
        /// all timing objects based on the time change.
        /// </summary>
        /// <remarks>
        /// The associated reference clock is used to determine the current time.
        /// The new position of the clock will be equal to the difference between the
        /// starting system time and the current system time. The time manager requires
        /// the system time to move forward.
        /// </remarks>
        //[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking
        public void Tick()
        {
            try
            {
#if DEBUG
                // On a regular interval, clean up our tables of known
                // timelines and clocks
                if (++_frameCount >= 1000) // Should be about once every 10s
                {
                    Timeline.CleanKnownTimelinesTable();
                    System.Windows.Media.Animation.Clock.CleanKnownClocksTable();
                    _frameCount = 0;
                }
#endif // DEBUG
                // Don't need to worry about needing a tick sooner
                _nextTickTimeQueried = false;

                // Mark the tree as clean immediately. If any changes occur during
                // processing of the tick, the tree will be marked as dirty again.
                _isDirty = false;

                // No effect unless we are in the running state
                if (_timeState == TimeState.Running)
                {
                    // Figure out the current time
                    _globalTime = GetCurrentGlobalTime();

                    // Start the tick
                    _isInTick = true;
                }

                // Trace the start of the tick and pass along the absolute time to which
                // we are ticking.
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnimation | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WClientTimeManagerTickBegin, (_startTime + _globalTime).Ticks / TimeSpan.TicksPerMillisecond);

                // Run new property querying logic on the timing tree
                if (_lastTimeState == TimeState.Stopped && _timeState == TimeState.Stopped)  // We were stopped the whole time
                {
                    _currentTickInterval = TimeIntervalCollection.CreateNullPoint();
                }
                else  // We were not stopped at some time, so process the tick interval
                {
                    _currentTickInterval = TimeIntervalCollection.CreateOpenClosedInterval(_lastTickTime, _globalTime);

                    // If at either tick we were stopped, add the null point to represent that
                    if (_lastTimeState == TimeState.Stopped || _timeState == TimeState.Stopped)
                    {
                        _currentTickInterval.AddNullPoint();
                    }
                }

                // Compute the tree state, using _currentTickInterval to compute the events that occured
                _timeManagerClock.ComputeTreeState();

                // Cache TimeManager state at this time
                _lastTimeState = _timeState;

                // When the tick is done, we raise timing events
                RaiseEnqueuedEvents();
            }
            finally
            {
                _isInTick = false;

                // Cache the tick time
                _lastTickTime = _globalTime;

                //trace the end of the tick
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnimation | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WClientTimeManagerTickEnd);
            }

            // At the end of every tick clean up GC'ed clocks, if necessary
            CleanupClocks();
        }