Windows Message Queuing Service

I want to write a Windows service in .Net 2.0 that listens and processes a message queue (MSMQ).

Instead of reinventing the wheel, can someone post an example of a better way to do this? It should process things one at a time, never in parallel (e.g. threads).

In fact, I want him to poll the queue, if there is anything there, process it, remove it from the queue and repeat. I want to do this with system efficiency.

Thanks for any suggestions!

+1
source share
2 answers

, . , , , .

http://www.codeproject.com/KB/cs/mgpmyqueue.aspx, MSDN .. http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue_events.aspx

Microsoft :

           ....
           // Create an instance of MessageQueue. Set its formatter.
           MessageQueue myQueue = new MessageQueue(".\\myQueue");
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(String)});

            // Add an event handler for the ReceiveCompleted event.
            myQueue.ReceiveCompleted += new 
                ReceiveCompletedEventHandler(MyReceiveCompleted);

            // Begin the asynchronous receive operation.
            myQueue.BeginReceive();
            ....


        private static void MyReceiveCompleted(Object source, 
            ReceiveCompletedEventArgs asyncResult)
        {
            // Connect to the queue.
            MessageQueue mq = (MessageQueue)source;

            // End the asynchronous Receive operation.
            Message m = mq.EndReceive(asyncResult.AsyncResult);

            // Display message information on the screen.
            Console.WriteLine("Message: " + (string)m.Body);

            // Restart the asynchronous Receive operation.
            mq.BeginReceive();

            return; 
        }
+4

WCF http://msdn.microsoft.com/en-us/library/ms751514.aspx.

: , , .Net 2.0. , WCF - , .NET 3.0, .

+4

Source: https://habr.com/ru/post/1703959/


All Articles