【发布时间】:2010-10-15 03:03:18
【问题描述】:
我正在使用System.Threading.Tasks.Parallel.For 做一些重量级的处理。
我的代码是:
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;
}
我不希望在列表中得到空值,但我是。我一定是在搞砸index 的使用。有什么想法吗?
【问题讨论】:
-
c中的results.Add(c)是什么?