protected void DrainMessageQueueIfAny()
 {
     if (OnMessage != null && messageQueue.Count > 0)
     {
         DispatchEvent deliveryTask = new MessageListenerDispatchEvent(this);
         Session.Dispatcher.Enqueue(deliveryTask);
     }
 }
        protected void SendForDelivery(IMessageDelivery nmsDelivery)
        {
            this.messageQueue.Enqueue(nmsDelivery);

            if (this.OnMessage != null && pendingMessageDeliveryTasks < ExecutorThreshold)
            {
                AddTaskRef();
                DispatchEvent dispatchEvent = new MessageListenerDispatchEvent(this);
                Session.Dispatcher.Enqueue(dispatchEvent);
            }
            else if (pendingMessageDeliveryTasks < 0)
            {
                Tracer.ErrorFormat("Consumer {0} has invalid pending tasks count on executor {1}.", Id, pendingMessageDeliveryTasks);
            }
        }