G
GeezerButler
I am very new to threading.
I am having trouble deciding on which object i should obtain lock.
class MyClass
{
private ICollection<ClassB> myColl;
public void ModifyCollection()
{
lock(????)
{
//modify the collection
}
}
}
Should I obtain lock on myColl itself or should i introduce a new
private object syncRoot in my class and obtain a lock on that?
Note that ICollection<T> does not have any syncRoot member unlike
ICollection.
On the web, I could see that both these ways are used extensively.
But what would be the differences?
I am having trouble deciding on which object i should obtain lock.
class MyClass
{
private ICollection<ClassB> myColl;
public void ModifyCollection()
{
lock(????)
{
//modify the collection
}
}
}
Should I obtain lock on myColl itself or should i introduce a new
private object syncRoot in my class and obtain a lock on that?
Note that ICollection<T> does not have any syncRoot member unlike
ICollection.
On the web, I could see that both these ways are used extensively.
But what would be the differences?