I do not understand why other threads cannot access the section if they DO NOT also use lock on the section object. In other words, any other stream: Partitions[partNo] can access partion except when it is ALSO:
lock (p = Partitions[partNo]) { //DO SOM STUFF ONLY WHEN YOU GOT ACCESS TO THE LOCK }
To clarify:
The lock will only contain other threads that ALSO try to lock the same object. This does not prevent access from threads that are not trying to lock the object.
To correct this situation, you can use, perhaps, an event to block other threads from accessing the section object and set this event before you start serializing, and reset move or simply remove the object from ConcurrentDictionary while working on it and set it then. Only what suits your needs.
source share