Questions tagged [syncroot]
6 questions
21
votes
3 answers
Correct way to lock the dictionary object
In my code I have a static dictionary object
private static IDictionary< ConnKey, DbConnection > ConnectionList = new Dictionary< ConnKey, DbConnection >( );
which is throwing this error
System.IndexOutOfRangeException: Index was outside the…

Pawan Nogariya
- 8,330
- 12
- 52
- 105
7
votes
2 answers
Why lock on Collection.SyncRoot instead of just lock the collection?
I'm trying to understand the point of the syncroot in ICollection. Why not just lock the collection?
lock(myCollection)
{
//do stuff to myCollection
}
vs
lock(myCollection.SyncRoot)
{
//do stuff to myCollection
}

richard
- 12,263
- 23
- 95
- 151
3
votes
2 answers
Is the SyncRoot object really thread safe?
I am new to SyncRoot concept. As far I can tell, the object used for locking should be private.
However HashTable has a public property, SyncRoot, which is just a wrapper over a private SyncRoot object. It is recommended that you lock on…

D J
- 6,908
- 13
- 43
- 75
2
votes
1 answer
Lock entire Dictionary or part of before copying (SyncRoot)
I have 2 dictionaries in a scoped service within a Blazor server application I use to manage state for multi tenancy. It has come to my attention that there may be concurrency issues with users modifying the dictionaries on different threads.
public…

Pippo
- 1,439
- 1
- 18
- 35
2
votes
1 answer
Why is queue lock in this example necessary
I have got the example shown below. I cannot find out why there is lock on queue SyncRoot also while the both coherent algorithms are whole locked using the same object.
It is said that queue lock is necessary.
public class CrudeThreadPool
{
…

Yarl
- 728
- 1
- 7
- 26
2
votes
1 answer
SyncRoot property in Powershell
This question is regarding the function forward_dns from the following blog:
http://powershellmasters.blogspot.com/2009/04/nslookup-and-powershell.html
So say I have a piece of code in powershell that looks like this:
$cmd = "nslookup google.com "…

la11111
- 361
- 5
- 10