R
RedLars
This [1] article at msdn describes the lock statments and gives a few
guidelines. After reading that article I had two small questions.
1. What is the difference between
private List<string> list = new List<string>();
private object lock = new object();
public void Add(string str)
{
lock(lock) list.Add(str);
}
and
private List<string> list = new List<string>();
public void Add(string str)
{
lock(list) list.Add(str);
}
2. Why set an lockerObjects as readonly? What does that accomplish?
Are there any other guidelines to consider when using lock?
[1] - http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx
guidelines. After reading that article I had two small questions.
1. What is the difference between
private List<string> list = new List<string>();
private object lock = new object();
public void Add(string str)
{
lock(lock) list.Add(str);
}
and
private List<string> list = new List<string>();
public void Add(string str)
{
lock(list) list.Add(str);
}
2. Why set an lockerObjects as readonly? What does that accomplish?
Are there any other guidelines to consider when using lock?
[1] - http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx