I am using System.Threading.Tasks.Parallel.For
to do some heavyweight processing.
My code is:
int count = 10;
List<MyObj> results = new List<MyObj>();
Parallel.For(0, count, (index) =>
{
MyObj obj = GetMyObjMaybe();
if (obj != null)
results.Add(obj);
});
if (results.Contains(null))
{
//break here, and it does
}
//sometimes contains null objects
return results;
}
I wouldn't expect to be getting null in the List, but I am. I must be botching the use of index
somehow. Any ideas?