/ Published in: C#
Counting Messages in an MSMQ MessageQueue from C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
protected Message PeekWithoutTimeout(MessageQueue q, Cursor cursor, PeekAction action) { Message ret = null; try { } catch (MessageQueueException mqe) { if (!mqe.Message.ToLower().Contains("timeout")) { throw; } } return ret; } protected int GetMessageCount(MessageQueue q) { int count = 0; Cursor cursor = q.CreateCursor(); Message m = PeekWithoutTimeout(q, cursor, PeekAction.Current); if (m != null) { count = 1; while ((m = PeekWithoutTimeout(q, cursor, PeekAction.Next)) != null) { count++; } } return count; }