コード例 #1
0
ファイル: MicroClock.cs プロジェクト: Landrash/ZoneLighting
 public void Timer_MicroTimerElapsed(object sender, MicroTimerEventArgs timerEventArgs)
 {
     if (Action == null)
     {
         throw new Exception("Action cannot be null.");
     }
     Action(timerEventArgs);
 }
コード例 #2
0
ファイル: MilliTimer.cs プロジェクト: Landrash/ZoneLighting
        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();
        }
コード例 #3
0
 public void Timer_MilliTimerElapsed(object sender, MicroTimerEventArgs timerEventArgs)
 {
     Action(timerEventArgs);
 }