The problem is that you're locking on a different object every time, so none of your Synclock blocks is associated with any other. Each time you call Synchronized you're creating a new object. Besides that, you're not supposed to lock on the result of Synchronized. If you read the documentation for the Synchronized method you'll see that in the code example they provide they lock on the Queue's SyncRoot property, which you do correctly in only one place.
As far as I can tell, the only reason you've declared that Queue is to use it to synchronise access to the SortedList. That's not the way to go. If you want to synchronise access to the SortedList then just create a object to use for locking:Now you lock on that syncRoot variable in EVERY SyncLock block so that they're all associated with each other and then only one of them at a time can be entered.vb.net Code:
Private syncRoot As New Object




Reply With Quote