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(); }
public void PostMessage(Message message) { lock (this) { while (this.messages.Count >= this.maxsize) Monitor.Wait(this); this.messages.Enqueue(message); Monitor.PulseAll(this); } }
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()); }
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()); }
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? }