Dequeue from messageQueue in the PeekCompleted Method

Posted by Fraga on Stack Overflow See other posts from Stack Overflow or by Fraga
Published on 2012-06-29T00:03:09Z Indexed on 2012/09/25 15:37 UTC
Read the original article Hit count: 231

Filed under:
|
|

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();
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about message-queue