Exemple #1
0
        public void TestLargeNumberWithPeriod()
        {
            _hash  = new Hashtable();
            _order = new ArrayList();
            for (int i = 0; i < 10000; i++)
            {
                SimpleTimer t = new SimpleTimer(Callback, i, 200, 0);
                t.Start();
            }

            for (int i = 0; i < 5; i++)
            {
                object      state = new object();
                SimpleTimer t     = new SimpleTimer(PeriodCallback, state, 50, 50);
                lock (_sync) {
                    _hash[state] = t;
                }
                t.Start();
            }

            Thread.Sleep(500);

            Assert.AreEqual(_order.Count, 10000, "Should be 10000");
            foreach (object o in _hash.Keys)
            {
                if (o is SimpleTimer)
                {
                    Assert.AreEqual((int)_hash[o], 5, "Should be 5");
                }
            }
        }
Exemple #2
0
        public void Schedule(FuzzyEvent e)
        {
#if BRUNET_SIMULATOR
            int         delay = (int)(e.End - DateTime.UtcNow).TotalMilliseconds;
            SimpleTimer st    = new SimpleTimer(FuzzyEventRunner, e, delay, 0);
            st.Start();
#else
            _incoming_events.Enqueue(e);
#endif
        }
Exemple #3
0
        public void PeriodCallback(object state)
        {
            SimpleTimer t     = _hash[state] as SimpleTimer;
            int         calls = 0;

            lock (_sync) {
                if (_hash.Contains(t))
                {
                    calls = (int)_hash[t];
                }
                _hash[t] = ++calls;
            }

            if (calls == 5)
            {
                t.Stop();
            }
        }
Exemple #4
0
        public void TestDipose()
        {
            _order = new ArrayList();
            for (int i = 0; i < 100; i++)
            {
                SimpleTimer t = new SimpleTimer(Callback, i, 100 + i, 0);
                t.Start();
                if (i % 2 == 0)
                {
                    t.Stop();
                }
            }

            Thread.Sleep(500);
            foreach (int val in _order)
            {
                Assert.IsTrue(val % 2 == 1, "Even value got in...");
            }
            Assert.AreEqual(_order.Count, 50, "Should be 50 in _order");
        }