1

I am trying to run in a Parallel foreach loop on all messages I have in my queue, but I am getting this error:

Error: Property Body was not retrieved when receiving the message. Ensure that the PropertyFilter is set correctly.

When I do the same loop with a foreach (without the parallel), it all works good.

Any idea what should I do to solve this issue?

PHeiberg
  • 29,411
  • 6
  • 59
  • 81
m0fo
  • 2,179
  • 6
  • 33
  • 43
  • 1
    Do you have any code to show? According to [MSDN](http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue(v=vs.100).aspx) only the `GetAllMessages` method is thread safe. The thread safe way for reading the queue asynchronously seems to be shown [here](http://stackoverflow.com/a/5276822/66849). – PHeiberg Aug 17 '12 at 22:04
  • Related question: http://stackoverflow.com/questions/5503954/how-to-process-msmq-messages-in-parallel – PHeiberg Aug 17 '12 at 22:30
  • @Ido Lazar: Are you just viewing the messages or removing them from the queue? – Dominic Zukiewicz Aug 27 '12 at 10:31

3 Answers3

5

Look like you are using not thread safe method, as per msdn

Only the GetAllMessages method is thread safe

GSerjo
  • 4,725
  • 1
  • 36
  • 55
2

Peek() and Receive() (and variations thereof) are not thread safe. You'll need to come up with a blocking mechanism in order to avoid collisions.

kprobst
  • 16,165
  • 5
  • 32
  • 53
1

Parallel processing will not work for taking messages off the queue as it is sequential and (if configured) transactional.

If you remove A and B, and processing for A fails, it would be returned to the queue - but B has been removed as well?

GetAllMessages() will return all of them, but will not remove them. You need to use Receive() for each message individually to remove it completely from the queue.

Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61