I have two component. One is Window application and other is Window Service.
Window Application writing to Message Queue(MSMQ) and Service is reading it and process the message.
Should service always keep looking to queue for new message...In terms of code should I
use infinite while
loop or a Timer
OR
is there any event or callback on queue for new message added to queue? So that when window application add a new message to queue, Service can know.
This all I am asking to make my application efficient so if there is any other way to achieve this you can suggest.
Thanks for reading
Asynchronous messaging. With MSMQ asynchronous messaging, a client application can send a message to a server and return immediately, even if the target computer or server program is not responding.
Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues.
You do not need any event or loop. Receive
method will read from the queue and if the queue is empty it will block until a new message is added. If you need to do something else in the meantime, put the receiving code in a separate thread.
You can also use asynchronous approach by using BeginReceive
. This will actually raise an event when message has been read from the queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With