Say I have a List
of values that I accessed by different threads. So I make it thread safe by doing something like this:
private static object syncObject;
syncObject = new Object();
public List<double> MyList
{
get
{
lock(syncObject) { return myList;}
}
set
{
lock(syncObject) { myList = value;}
}
}
If in one of my functions, I need to access the Count
attribute of the List
, it may not be thread safe anymore. So how do I write it such that even when accessing the attributes, it will be thread safe?