Exemplo n.º 1
0
 public void Timer_MicroTimerElapsed(object sender, MicroTimerEventArgs timerEventArgs)
 {
     if (Action == null)
     {
         throw new Exception("Action cannot be null.");
     }
     Action(timerEventArgs);
 }
Exemplo n.º 2
0
        protected override void NotificationTimer(ref long timerIntervalInMicroSec, ref long ignoreEventIfLateBy, ref bool stopTimer)
        {
            int  timerCount       = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();
            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;

                long timerIntervalInMicroSecCurrent =
                    System.Threading.Interlocked.Read(ref timerIntervalInMicroSec);
                long ignoreEventIfLateByCurrent =
                    System.Threading.Interlocked.Read(ref ignoreEventIfLateBy);

                nextNotification += timerIntervalInMicroSecCurrent;
                timerCount++;
                long elapsedMicroseconds = 0;

                while ((elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                       < nextNotification)
                {
                    Thread.Sleep(ThreadSleepTime);
                }

                long timerLateBy = elapsedMicroseconds - nextNotification;

                if (timerLateBy >= ignoreEventIfLateByCurrent)
                {
                    continue;
                }

                MicroTimerEventArgs microTimerEventArgs =
                    new MicroTimerEventArgs(timerCount,
                                            elapsedMicroseconds,
                                            timerLateBy,
                                            callbackFunctionExecutionTime);
                MilliTimerElapsed(this, microTimerEventArgs);
            }


            microStopwatch.Stop();
        }
Exemplo n.º 3
0
 public void Timer_MilliTimerElapsed(object sender, MicroTimerEventArgs timerEventArgs)
 {
     Action(timerEventArgs);
 }