Is MSMQ thread safe?

I have several processes controlling the MSMQ queue. I want to perform multi-step operations, for example, first look at the message, and then, based on some criteria, get the message. A single message may convey the acceptance criteria of several processes so that more than one process tries to receive the same message. Will these operations be safe threads? If not, then what should I do to prevent one process from receiving a message that another process has already received?

+7
multithreading msmq
source share
3 answers

the operations themselves are thread safe. However, if you are performing a multi-step operation, you may find that the results are incompatible (for example, browsing to see if the data is in the queue, and then calling to receive the data, only to find it is no longer there).

+5
source share

According to MSDN :

Only the following methods are thread safe: BeginPeek, BeginReceive, EndPeek (IAsyncResult), EndReceive (IAsyncResult), GetAllMessages, Peek and Receive.

+14
source share

You might be interested in a blog post I wrote on this topic.

In short, the MSMQ C ++ API is thread safe, but not all System.Messaging methods are thread safe. In a blog post, I discuss how to invoke MessageQueue.Send in streaming mode.

+6
source share

All Articles