Yes. You can use any object, as long as you use the same one and you know
it does not change behind the covers somehow. For clarity, I would use my
own syncRoot in the class such as this simple example:
public class Class1
{
private readonly object syncRoot = new object();
private readonly List<int> list = new List<int>();
public object SyncRoot
{
get{return this.syncRoot;}
}
public void Add(int i)
{
lock(syncRoot)
{
list.Add(i);
}
}
//...
}
--
William Stacey [MVP]
|
| | > In 1.1, IIRC, there would be no difference as list.SyncRoot was "this".
| > However, in 2.0, SyncRoot is not "this" but a seperate object. Use
| > SyncRoot
| > if you want to lock on that. However, I would just use my own syncRoot
| > object in your containing class.
| >
|
| So it doesn't matter which way I do it as long as I always do it the same
| way. Is that right?
|
|