Created
October 31, 2013 09:45
-
-
Save rod-dot-codes/7247055 to your computer and use it in GitHub Desktop.
Read the last message of a C# Queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MessageQueue queue = new MessageQueue("FormatName:DIRECT=OS:<queue_address>") | |
{ | |
MessageReadPropertyFilter = new MessagePropertyFilter | |
{ | |
ArrivedTime = true, | |
Body = true | |
} | |
}; | |
Console.WriteLine(queue.CanRead.ToString()); | |
Console.WriteLine(queue.CanWrite.ToString()); | |
var messages = queue.GetAllMessages(); | |
var m = messages.Last(); | |
m.Formatter = new System.Messaging.XmlMessageFormatter(new String[] {}); | |
StreamReader sr = new StreamReader(m.BodyStream); | |
string ms = ""; | |
string line; | |
while (sr.Peek() >= 0) | |
{ | |
ms += sr.ReadLine(); | |
} | |
Console.Write(HttpUtility.HtmlDecode(ms)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh ya, requires you to import
System.Messaging
System.Web
and import the relative DLL's in LinqPad.