Beispiel #1
0
        /// <summary>
        /// Method is used to determin is the timer's TriggerInterval has elapsed based on the given time Now and the recorded time of the last occurance.
        /// If the timer has elapsed and the timer is configured to AutoReset, method will add the TriggerInterval to the last occurance to the timestamp
        /// of the current occurance (even if now is after that occurance).  Then if this newly advanced timer has already expired then the method Reset's
        /// the timer to occur at TimerInterval from the given now value.
        /// <para/>This method returns false if the timer is not running (either by being explicitly Started or by having the TriggerInterval be zero with the non-default ZeroTriggerIntervalRunsTimer behavior selected).
        /// non-AutoReset timers will continue to return true once they have triggered until some other action is taken to change, reset or start the timer.
        /// </summary>
        /// <param name="now">Caller provided QpcTimeStamp value that defines when the timer is evaluated against and provides the base time for a Reset style advance when appropriate.</param>
        /// <param name="enableApplyOnCallChanges">Pass this as true to enable application of "on call" changes to the state of the QpcTimer.  Pass this as false if you are intending to "peak" at the state of the timer (aka for debugger viewable properties)</param>
        public bool GetIsTriggered(QpcTimeStamp now, bool enableApplyOnCallChanges = true)
        {
            bool isTimerRunning, isTimerTriggered;

            InnerGetIsTriggered(now, out isTimerRunning, out isTimerTriggered);

            if (!isTimerRunning)
            {
                return(false);
            }

            if (isTimerTriggered && !lastTriggered)
            {
                ElapsedTimeAtLastTrigger = GetElapsedTime(now, enableApplyOnCallChanges: enableApplyOnCallChanges);
            }

            lastTriggered = isTimerTriggered;

            if (isTimerTriggered && AutoReset && enableApplyOnCallChanges)
            {
                // update the lastTriggerTimestamp to match the incoming nextTriggerTimestamp
                lastTriggerTimeStamp = !nextTriggerTimeStamp.IsZero ? nextTriggerTimeStamp : qtcNegativeEpsilon;

                // add the interval to the nextTriggerTimestamp
                nextTriggerTimeStamp.Add(triggerIntervalInSec);

                // if the new nextTriggerTimestamp is already past then reset/restart the timer to expire after the full triggerInterval has elapsed from now.
                if (nextTriggerTimeStamp < now)
                {
                    Start(now);
                }
            }

            return(isTimerTriggered);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the Age of the given <paramref name="qpcTimeStamp"/>.  Caller can optionally provide the current timestamp against which the age is to be measured.
        /// </summary>
        public static TimeSpan Age(this QpcTimeStamp qpcTimeStamp, QpcTimeStamp?qpcTimeStampNowIn = null)
        {
            QpcTimeStamp qpcTimeStampNow = qpcTimeStampNowIn ?? QpcTimeStamp.Now;

            TimeSpan age = (qpcTimeStampNow - qpcTimeStamp);

            return(age);
        }
Beispiel #3
0
        /// <summary>
        /// Starts the timer to trigger after the TriggerInterval has elpased from the given starting timestamp.
        /// </summary>
        public QpcTimer Start(QpcTimeStamp now)
        {
            ElapsedTimeAtLastTrigger = TimeSpan.Zero;

            lastTriggerTimeStamp = (!now.IsZero) ? now : qtcNegativeEpsilon;
            nextTriggerTimeStamp = now + triggerIntervalInSec;

            return(this);
        }
Beispiel #4
0
 /// <summary>
 /// Method is used to reset (and start) the timer.
 /// If <paramref name="triggerImmediately"/> is false then this method will start the timer to trigger after TriggerInterval TimeSpan has elpased (from now).  (This is a synonym for Start(now)).
 /// If <paramref name="triggerImmediately"/> is true then this method will start the timmer to trigger immediately.
 /// </summary>
 public QpcTimer Reset(QpcTimeStamp now, bool triggerImmediately = false)
 {
     if (!triggerImmediately)
     {
         return(Start(now));
     }
     else
     {
         return(Start(now - TriggerInterval));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Gives the Elapsed Time between the given now value and the time that the timer last expired as a TimeSpan value.
        /// <para/>If the IntervalMeasurmentTimer behavior is selected and the timer is running then the use of this method will also Reset the timer
        /// </summary>
        /// <param name="now">Caller provided QpcTimeStamp value that defines when the timer is evaluated against and provides the base time for a Reset style advance when appropriate.</param>
        /// <param name="enableApplyOnCallChanges">Pass this as true to enable application of "on call" changes to the state of the QpcTimer.  Pass this as false if you are intending to "peak" at the state of the timer (aka for debugger viewable properties)</param>
        public TimeSpan GetElapsedTime(QpcTimeStamp now, bool enableApplyOnCallChanges = true)
        {
            bool     started = Started;
            TimeSpan result  = (started || !ElapsedTimeIsZeroWhenStopped) ? (now - lastTriggerTimeStamp) : TimeSpan.Zero;

            if (IsIntervalMeasurementTimer && started && enableApplyOnCallChanges)
            {
                Reset(now);
            }

            return(result);
        }
Beispiel #6
0
 /// <summary>Returns the Max of the given QpcTimeStamp values</summary>
 public static QpcTimeStamp Max(this QpcTimeStamp a, params QpcTimeStamp[] more)
 {
     return(a.Concat(more).Max());
 }
Beispiel #7
0
 /// <summary>Returns the Max of the given QpcTimeStamp values</summary>
 public static QpcTimeStamp Max(this QpcTimeStamp a, QpcTimeStamp b, QpcTimeStamp c)
 {
     return(a.Max(b).Max(c));
 }
Beispiel #8
0
 /// <summary>Returns the Max of the given QpcTimeStamp values</summary>
 public static QpcTimeStamp Max(this QpcTimeStamp a, QpcTimeStamp b)
 {
     return((a >= b) ? a : b);
 }
Beispiel #9
0
 /// <summary>Returns the Min of the given QpcTimeStamp values</summary>
 public static QpcTimeStamp Min(this QpcTimeStamp a, QpcTimeStamp b, QpcTimeStamp c)
 {
     return(a.Min(b).Min(c));
 }
Beispiel #10
0
 /// <summary>Returns the Min of the given QpcTimeStamp values</summary>
 public static QpcTimeStamp Min(this QpcTimeStamp a, QpcTimeStamp b)
 {
     return((a <= b) ? a : b);
 }
Beispiel #11
0
 /// <summary>
 /// If the given <paramref name="qpcTimeStamp"/> value is non-zero (aka non-default) then this method returns its value, otherwise if it is zero then this method returns a new timestamp value obtained from QpcTimeStamp.Now.
 /// </summary>
 public static QpcTimeStamp MapDefaultToNow(this QpcTimeStamp qpcTimeStamp)
 {
     return(!qpcTimeStamp.IsZero ? qpcTimeStamp : QpcTimeStamp.Now);
 }
Beispiel #12
0
 private void InnerGetIsTriggered(QpcTimeStamp now, out bool isTimerRunning, out bool isTimerTriggered)
 {
     isTimerRunning   = (Started && (triggerIntervalInSec > 0.0) || (triggerIntervalInSec == 0.0 && ZeroTriggerIntervalRunsTimer));
     isTimerTriggered = isTimerRunning && (now >= nextTriggerTimeStamp) && !IsIntervalMeasurementTimer;
 }