Exemplo n.º 1
0
        public void PollOnce()
        {
            int count = 0;

            var timer = new NetMQTimer(TimeSpan.FromMilliseconds(50));
            timer.Elapsed += (a, s) =>
            {
                count++;

                if (count == 3)
                {
                    timer.Enable = false;
                }
            };

            // NOTE if the PollTimeout here is less than the timer period, it won't fire during PollOnce -- is this by design?

            using (var poller = new Poller(timer) { PollTimeout = 1000 })
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                poller.PollOnce();

                var pollOnceElapsedTime = stopwatch.ElapsedMilliseconds;

                Assert.AreEqual(1, count, "the timer should have fired just once during the call to PollOnce()");
                Assert.Less(pollOnceElapsedTime, 90, "pollonce should return soon after the first timer firing.");
            }
        }