Is there any event or callback in MSMQ to add a new message to the queue

I have two components. One is the Window application, and the other is the Window service. The application window is written to the message queue (MSMQ) and the service reads it and processes the message.
If the service will always look for a queue for a new message ... As for the code, I should / use an infinite while or Timer while
OR
is there any event or callback in the queue for a new message added to the queue? So when a window application adds a new message to the queue, the service can know.
That's all I ask to make my application effective, so if there is any other way to achieve this, you can suggest.
thank you for reading

+6
source share
1 answer

You do not need any event or loop. Receive will be read from the queue, and if the queue is empty, it will be blocked until a new message is added. If you need to do something else, add the receive code to a separate thread.

You can also use the asynchronous approach using BeginReceive . This will actually trigger an event when a message has been read from the queue.

+11
source

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


All Articles