Example #1
0
        public void Quit( )
        {
            // TODO: make cancellable
            OnContextStopping();
            Closing?.Invoke();

            eventPump.Stop();
        }
Example #2
0
        public void StartStopEventPump( )
        {
            ManualResetEventSlim signal = new ManualResetEventSlim(false);

            eventPump.EventPumpStateChanged += (arg) => {
                signal.Set();
            };

            Task task = Task.Factory.StartNew(() => eventPump.Start());

            signal.Wait();
            signal.Reset();

            Assert.IsTrue(eventPump.IsRunning);

            // let it run
            Thread.Sleep(500);

            eventPump.Stop();
            signal.Wait();

            Assert.IsFalse(eventPump.IsRunning);

            signal.Dispose();
            task.Dispose();
        }
        public void EventPumpQueueLength(int numberOfProducers, bool producerDelay)
        {
            EventQueue q = new EventQueue();

            EventProducer[] producers = new EventProducer[numberOfProducers];
            for (int i = 0; i < numberOfProducers; i++)
            {
                producers[i] = new EventProducer(q, i, producerDelay);
            }

            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "EventPumpQueueLength";
                pump.Start();

                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Start();
                }
                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Join();
                }
                pump.Stop();
            }
            Assert.That(q.Count, Is.EqualTo(0));

            foreach (EventProducer p in producers)
            {
                Console.WriteLine(
                    "#Events: {0}, MaxQueueLength: {1}", p.SentEventsCount, p.MaxQueueLength);
                Assert.IsNull(p.Exception, "{0}", p.Exception);
            }
        }
Example #4
0
 private void StopPump(EventPump pump, int waitTime)
 {
     pump.Stop();
     WaitForPumpToStop(pump, waitTime);
 }
 private static void StopPump(EventPump pump, int waitTime)
 {
     pump.Stop();
     WaitForPumpToStop(pump, waitTime);
 }
        public void EventPumpQueueLength(int numberOfProducers, bool producerDelay)
        {
            EventQueue q = new EventQueue();
            EventProducer[] producers = new EventProducer[numberOfProducers];
            for (int i = 0; i < numberOfProducers; i++)
            {
                producers[i] = new EventProducer(q, i, producerDelay);
            }

            using (EventPump pump = new EventPump(NullListener.NULL, q, false))
            {
                pump.Name = "EventPumpQueueLength";
                pump.Start();

                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Start();
                }
                foreach (EventProducer p in producers)
                {
                    p.ProducerThread.Join();
                }
                pump.Stop();
            }
            Assert.That(q.Count, Is.EqualTo(0));

            foreach (EventProducer p in producers)
            {
                Console.WriteLine(
                    "#Events: {0}, MaxQueueLength: {1}", p.SentEventsCount, p.MaxQueueLength);
                Assert.IsNull(p.Exception, "{0}", p.Exception);
            }
        }