예제 #1
0
        /// <summary>
        /// Initializes a new <see cref="MicroStopwatch"/> instance, sets the elapsed time property to zero,
        /// and starts measuring elapsed time.
        /// </summary>
        ///
        /// <param name="throwOnLowResolution">
        /// If true and <see cref="Stopwatch.IsHighResolution"/> is false, throws an exception.
        /// </param>
        /// <returns>A <see cref="MicroStopwatch"/> that has just begun measuring elapsed time.</returns>
        ///
        /// <exception cref="NotSupportedException">
        /// <see cref="Stopwatch.IsHighResolution"/> is false and <paramref name="throwOnLowResolution"/> is
        /// true.
        /// </exception>
        public static MicroStopwatch StartNew(bool throwOnLowResolution)
        {
            MicroStopwatch watch = new MicroStopwatch(throwOnLowResolution);

            watch.Start();
            return(watch);
        }
예제 #2
0
        void NotificationTimer(long lTimerInterval,
                               long lIgnoreEventIfLateBy, ref bool bStopTimer)
        {
            int  nTimerCount       = 0;
            long lNextNotification = 0;
            long lCallbackFunctionExecutionTime = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();

            while (!bStopTimer)
            {
                lCallbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - lNextNotification;
                lNextNotification += lTimerInterval;
                nTimerCount++;
                long lElapsedMicroseconds = 0;

                while ((lElapsedMicroseconds =
                            microStopwatch.ElapsedMicroseconds) < lNextNotification)
                {
                }

                long lTimerLateBy = lElapsedMicroseconds - (nTimerCount * lTimerInterval);

                if (lTimerLateBy < lIgnoreEventIfLateBy)
                {
                    MicroTimerEventArgs microTimerEventArgs =
                        new MicroTimerEventArgs(nTimerCount, lElapsedMicroseconds,
                                                lTimerLateBy, lCallbackFunctionExecutionTime);
                    MicroTimerElapsed(this, microTimerEventArgs);
                }
            }

            microStopwatch.Stop();
        }