zoukankan      html  css  js  c++  java
  • recycle process encounter a exception collection was modified enumeration operation might not execute

    在执行一个9万多的数据处理时报错,报错信息如下:

    recycle process encounter a exception collection was modified enumeration operation might not execute

    代码如下(示意代码)

    for(int i=0;i<dt.xxtable.rows.count;i++)
    
    {
    
        var query=listquery.where(查询条件);
    
        foreach(item in query)      
    
        {
    
          强类型DT.row row1=强类型DT.row.addnewrow();
    
          row1.beginedit();
    
          row1.a=item.a;
    
          row1.b=item.b;
    
          row1.endedit();
    
          强类型DT.xxtable.addxx_row(row1);
    
         } 
    
    }

    在网上找了N多办法,全列出来供各位参考:

    1、采用for循环而不采用foreach循环,这类主要针对的是循环体是LIST<>等集合的处理办法

    2、采用ReaderWriterLock,ReaderWriterLockSlim(.net4?)处理数据

    3、采用lock(object) 替换 lock(this)

    前人总结的这么多居然对我们的代码都无效,我K。

    解决办法:

    新建立一个原datatable的克隆,操作这个新的datatable,最后将原有的 DATASET.ADDROW(NEWROW)替换为DATASET.IMPORTROW(ROW);

    DataTable newdt=dt.xxxtable.clone();
    
    for(int i=0;i<dt.xxtable.rows.count;i++)
    
    {
    
        var query=listquery.where(查询条件);
    
        foreach(item in query)      
    
        {
    
          //强类型DT.row row1=强类型DT.row.addnewrow();
            强类型DT.row row1=newdt.NewRow() as 强类型DT.row ;
          row1.beginedit();
          row1.a=item.a;
          row1.b=item.b;
          row1.endedit();
           newdt.rows.add(row1);
         } 
         foreach(datarow row in newdt)
        {
              强类型DT.XXXtable.importrow(row);
        }
    
    
    }
  • 相关阅读:
    整数划分《递归法》
    hdu 1224 Free DIY Tour
    HTTP Response Status Code HTTP响应代码中文详解
    Webserive学习站点
    页面的回传与回调
    JS中apply和call函数的运用
    SOAP协议详解
    JS在firefox和IE下差异及解决方案
    关于路径的问题
    .NET中IDisposable接口的基本使用 (转)
  • 原文地址:https://www.cnblogs.com/forrestsun/p/2573357.html
Copyright © 2011-2022 走看看