Beispiel #1
0
        private void TimerEventTest(ITimer timer)
        {
            Console.WriteLine($"TimerEventTest {timer.GetType().Name}");
            timer.Interval = 5;
            timer.Start();

            Task.Run(() =>
            {
                var stopwatch = new HiResStopwatch();
                stopwatch.Start();

                var timerEvent = new TimerEvent(timer);
                var count      = 0;
                while (count++ < 400)
                {
                    timerEvent.WaitOne();
                    Console.WriteLine($"TimerEventTest TickCount {count}, Timer = {stopwatch.ElapsedMicroseconds:#,0} µs");
                }

                timerEvent.Dispose();
                stopwatch.Stop();
            }).Wait();

            Console.WriteLine("Stopping...");

            timer.Dispose();
        }
Beispiel #2
0
        private void TimerTest(ITimer timer)
        {
            Console.WriteLine($"TimerTest {timer.GetType().Name}");
            var stopwatch = new HiResStopwatch();

            stopwatch.Start();

            timer.Interval = 5;
            timer.Elapsed += (sender, args) => OnTimerTick(stopwatch, args);
            timer.Start();

            // Do something whilst events happening, for demo sleep 2000ms (2sec)
            Thread.Sleep(2000);

            Console.WriteLine("Stopping...");

            timer.Dispose();
        }