public MessageSchedule(IPriortyQueue <MessageInfo <TMessage> > queue, IMessageRouter host) { if (!queue.IsSynchronized) { MessageQueue = PriorityQueue <MessageInfo <TMessage> > .Synchronized(queue); } else { MessageQueue = queue; } thread = new Thread(delegate() { IsRuning = true; MessageInfo <TMessage> item = null; while (true) { if (!IsRuning) { return; } while (MessageQueue.Count > 0) { //Thread.Sleep(MillisecondsTimeout); if ((item = MessageQueue.Pop()) != null) { host.Send(item.Sender, item.Message, true); } Thread.Sleep(MillisecondsTimeout); } } }); thread.IsBackground = true; thread.Name = "MessageManager.MessageQueue.Thread"; thread.Start(); }
public T Pop() { lock (InnerQueue.SyncRoot) return(InnerQueue.Pop()); }