日期:2014-05-17  浏览次数:20983 次

Parallel.For无法continue怎么办
 Parallel.For(0, r1.LastCol, (i, loopState) =>
            {                var item = myType.GetProperty(r1.getText(0, i));
                if (item == null)
                {
                    loopState.Break();
                }
  if (item.Name.Contains("比例"))
                    {

item == null时还是会运行到item.Name.Contains.结果出错了

------解决方案--------------------
 Parallel.For(0, r1.LastCol, (i, loopState) =>
            {                var item = myType.GetProperty(r1.getText(0, i));
                if (item == null)
                {
                    loopState.Stop();
                    break;
                }
  if (item.Name.Contains("比例"))
                    {


http://msdn.microsoft.com/zh-cn/library/dd460721.aspx
------解决方案--------------------
把loopState.Break();换成return;
------解决方案--------------------
Parallel.For(0, r1.LastCol, (i, loopState) =>
            {                var item = myType.GetProperty(r1.getText(0, i));
                if (item == null)
                {
                    loopState.Stop();
                    return; //写错了 - -!
      &n