Hi,
I'm beginning to experiment with Microsoft Message Queues and have run into a simple
problem.
I would like a Windows Service I'm creating to monitor continuously a MSMQ, and upon
receiving a message, call another method.
How do I get the service to continually check the queue?
I've tried putting the Receive() function in an infinite loop in the OnStart method
(see code), but of course that keeps the service from installing!
I'd appreciate any advice!
Bar
*** my code ***
protected override void OnStart(string[] args)
{
string queuePath = @".\private$\myQueue";
MessageQueue myQueue;
if (! MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath);
}
myQueue = new MessageQueue(queuePath);
// ...and now the infinite loop...
while (true)
{
Message myMessage = myQueue.Receive();
ProcessMessage(myMessage.Body.ToString()); // call to another method
}
}