Is there any way to check if open MSMQ is empty? For private MSMQ, this is easy:
private bool IsQueueEmpty(string path) { bool isQueueEmpty = false; var myQueue = new MessageQueue(path); try { myQueue.Peek(new TimeSpan(0)); isQueueEmpty = false; } catch (MessageQueueException e) { if (e.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { isQueueEmpty = true; } } return isQueueEmpty; }
How do I do the same validation for public MSMQ? If I try to check public MSMQ with the code above, this will give me an error at its peak:
System.ArgumentOutOfRangeException: The length cannot be less than zero.
source share