We have queued messages using C # Queue. We know that we have only one consumer to receive an available message from the queue for processing using a loop while. We also know that there is only one producer to send a message to the queue.
We have lockin the specified message queue to make sure that the consumer and the manufacturer cannot simultaneously access the queue.
My question is what is lockneeded? If it Queueincreases its Countproperty AFTER , the element is actually added, and if the consumer checks Countbefore retrieving, the consumer should receive the full message element, even if we don’t have that lock. Correctly? Therefore, we will not encounter the problem of partial communication. Then we can get rid of what lock?
That lockwill slow down the system, and sometimes we can see that the load flow is blocked for a while, because we have a very heavy manufacturer.
EDIT:
Unfortunately, we are using .Net 3.5.
source
share