How can I modify the following code block so it does not rely on try/catch block and IOTimeout. This function gets called every 1 minute. so I just want to process the list of Id's that got queued after the last call to this.
If I just received a null when no messages were waiting in the queue, that would've solved my issue but the API http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.receive.aspx shows all the signatures of receive are synchronous (I can not block the thread) or with a MessageQueueException exceptions which I'm having to tap into by try/catch block. Which I wanted to avoid after reading some article suggesting not to use try/catch to control program flow.
#pragma warning disable
public void ConsumeEvents2()
{
var listOfJobs = new List<int>();
try {
while (true) {
// receive all messages and add in a list to process later
Message message = messageQueue.Receive(new TimeSpan(0,0,3));
JobEvent evt = (JobEvent)message.Body;
listOfJobs.Add(evt.DataNumber);
}
} catch (MessageQueueException e) {
if (e.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) {
// process the numbers received
ProcessJobList(listOfJobs);
return;
}
throw;
}
}
#pragma warning restore