Dequeue from messageQueue in the PeekCompleted Method
- by Fraga
i'm reading messages from MessageQueue using PeekCompleted, i do my process here and if everything go right, I need to remove it from the Queue! currenty i am using MyMessageQueue.Receive() and it works, but is this a reliable way of making sure each message will be processed right?
MessageQueue MyMessageQueue;
public Form1()
{
InitializeComponent();
MyMessageQueue = new MessageQueue(@".\private$\Dms");
MyMessageQueue.PeekCompleted += new PeekCompletedEventHandler(MessageQueue_PeekCompleted);
MyMessageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
MyMessageQueue.BeginPeek();
}
void MessageQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
{
try
{
Debug.WriteLine("ToProcess:" + e.Message.Body);
//Long process that maybe fail
MyMessageQueue.Receive();
}
finally
{
MyMessageQueue.BeginPeek();
}
}