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

1

8

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

Halves answered 11/7, 2012 at 16:29 Comment(0)
F
13

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.

Flotation answered 11/7, 2012 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.