Recently my co-worker showed me a block of code that was not working correctly:
public class SomeClass
{
private IList _categories;
publ
If you sure that its because of threading issue, then use the lock keyword. I believe this should work.
public class SomeClass
{
private IList _categories;
public void SetCategories()
{
lock(this)
{
_categories = GetCategories() ?? new List();
DoSomethingElse();
}
}
public IList GetCategories()
{
return RetrieveCategories().Select(Something).ToList();
}
}