在C#.Net中,处理大数据与数据库交互时,采用分批进行,提高性能,减轻内存压力
日期:2019/12/29 发布人:润宇软件
浏览量:13
int batchMax = 100;//以一百条一次,也可以自由设置
int curLoc =0;
ArrayList personList = null;
//分批处理
while(true)
{
#region 进行分批
if(curLoc + batchMax>arrPersonId.Count)
{
personList = arrPersonId.GetRange(curLoc,arrPersonId.Count - curLoc);
curLoc = arrPersonId.Count;
}
else
{
personList = arrPersonId.GetRange(curLoc,batchMax);
curLoc = curLoc + batchMax;
}
if(personList == null || personList.Count ==0)
{
break;
}
#endregion
//将新得到的数据集合personList,再去和数据进行交互,减轻了一次查询的压力,同时也减少了一笔笔循环的低性能
}
