我正在尝试创建一个数据表并将单行加载到数据表中。我正在使用此数据表作为表类型参数。但是这个方法包含在一个 ParallelProcessor 中。一些记录正在更新,但对于一些记录,我得到以下内存不足异常。
public DataTable Getrecords(List<testData> testData)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
var data = testData.Select(x => x.ID);
foreach (var item in data)
{
DataRow dr = table.NewRow();
dr["ID"] = item;
table.Rows.Add(dr);
}
return table;
}
下面是我得到的一些记录的错误
System.OutOfMemoryException:引发了“System.OutOfMemoryException”类型的异常。 在 System.Data.RBTree
1.AllocPage(Int32 大小) 在 System.Data.RBTree`1.GetNewNode(K 键) 在 System.Data.DataTable.SetNewRecordWorker(DataRow 行,Int32 proposedRecord,DataRowAction 操作,布尔值 isInMerge,布尔值 suppressEnsurePropertyChanged,Int32 位置,布尔值 fireEvent,异常和 deferredException) 在 System.Data.DataTable.InsertRow(DataRow 行,Int64 proposedID,Int32 pos,Boolean fireEvent)1.TreePage..ctor(Int32 size) at System.Data.RBTree
它在某些环境下工作得很好。