예제 #1
0
        public void TestPostAfterStartInAnotherThread()
        {
            using (MessageQueue queue = new MessageQueue())
            {
                object received = null;
                queue.MessageReceived += delegate(object sender, MessageQueueEventArgs e)
                {
                    received = e.Message;
                };

                object message = new object();
                queue.StartInAnotherThread();
                queue.Post(message);
                queue.TerminateAndWait();

                Assert.AreSame(message, received);
            }
        }
예제 #2
0
        public void TestContinueQueueAfterTerminate()
        {
            using (MessageQueue queue = new MessageQueue())
            {
                object received = null;
                queue.MessageReceived += delegate(object sender, MessageQueueEventArgs e)
                {
                    received = e.Message;
                };

                queue.StartInAnotherThread();

                // Keep the queue busy for 100 ms
                queue.Post(x => Thread.Sleep(100), null);

                // Post a message that will be quickly handled as soon as the above sleep finishes
                object message1 = new object();
                queue.Post(message1);

                // Post a termination request to the queue.
                queue.Terminate();

                // Post a second message - because this is after the Terminate it will not be
                // processed until the queue is restarted.
                object message2 = new object();
                queue.Post(message2);

                // Allow time for the messages processes so far (up to the terminate) to be processed.
                Thread.Sleep(500);

                // message1 should have been processed, but not message2.
                Assert.AreSame(message1, received);

                // Once we restart the queue, message2 should be processed.
                queue.StartInAnotherThread();
                queue.TerminateAndWait();
                Assert.AreSame(message2, received);
            }
        }
예제 #3
0
        public void BookExample()
        {
            using (MessageQueue queue = new MessageQueue())
            {
                queue.StartInAnotherThread();

                double square = 0;
                queue.MessageReceived += delegate(object sender, MessageQueueEventArgs e)
                {
                    double value = (double)e.Message;
                    square = value * value;
                };

                queue.Post(5.0);
                queue.TerminateAndWait();

                Assert.AreEqual(25.0, square);
            }
        }
예제 #4
0
        public void TestCantStartQueueTwice()
        {
            using (MessageQueue queue = new MessageQueue())
            {
                queue.StartInAnotherThread();

                try
                {
                    queue.StartInCurrentThread();
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                }

                try
                {
                    queue.ProcessQueue();
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                }

                try
                {
                    queue.StartInAnotherThread();
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                }
            }
        }
예제 #5
0
        public void TestProcessQueue()
        {
            using (MessageQueue queue = new MessageQueue())
            {

                object received = null;
                queue.MessageReceived += delegate(object sender, MessageQueueEventArgs e)
                {
                    received = e.Message;
                };

                object message = new object();
                queue.Post(message);

                queue.ProcessQueue();
                Assert.AreSame(message, received);
            }
        }
예제 #6
0
 public ShapefileWorker(Context context, Ellipsoid globeShape, MessageQueue doneQueue)
 {
     _context = context;
     _globeShape = globeShape;
     _doneQueue = doneQueue;
 }