Пример #1
0
        public void CreateAndUseMessageQueue()
        {
            MessageQueue queue = new MessageQueue(1);
            Message message = new Message(null, new Method("name"), new object[] { 1, 2 });

            Thread thread = new Thread(new ThreadStart(delegate { queue.PostMessage(message); }));
            thread.Start();

            Message result = queue.GetMessage();
        }
Пример #2
0
        public void PostMessage(Message message)
        {
            lock (this)
            {
                while (this.messages.Count >= this.maxsize)
                    Monitor.Wait(this);

                this.messages.Enqueue(message);
                Monitor.PulseAll(this);
            }
        }
Пример #3
0
        public void CreateAndUseMessageQueueWithTenMessages()
        {
            MessageQueue queue = new MessageQueue(10);
            Message message = new Message(null, new Method("name"), new object[] { 1, 2 });

            for (int k = 1; k <= 10; k++)
                queue.PostMessage(message);

            for (int k = 1; k <= 10; k++)
                Assert.AreEqual(message, queue.GetMessage());
        }
Пример #4
0
        public void CreateAndUseMessageQueueWithMoreEntriesThanSize()
        {
            MessageQueue queue = new MessageQueue(10);
            Message message = new Message(null, new Method("name"), new object[] { 1, 2 });

            Thread thread = new Thread(new ThreadStart(delegate
            {
                for (int k = 1; k <= 20; k++)
                    queue.PostMessage(message);
            }));

            thread.Start();

            for (int k = 1; k <= 20; k++)
                Assert.AreEqual(message, queue.GetMessage());
        }
Пример #5
0
 public override object ExecuteMethod(Interpreter interpreter, IMethod method, object[] arguments)
 {
     Message message = new Message(interpreter.Machine, method, arguments);
     this.queue.PostMessage(message);
     return null;    // TODO what to return?
 }