简体   繁体   中英

is there any event or callback on MSMQ for new message added to queue

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM