I am trying to create a datatable and load a single row in to the datatable. I am using this datatable as table type parameter. But this method is enclosed in a ParallelProcessor. Some records are being updated but for some I get the below Out of memory exception.
ParallelProcessor.EnqueueAsync(() =>
{
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;
}
});
ParallelProcessor.WaitForQueueCompletion();
Below is the error which I get for some records
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Data.RBTree
1.TreePage..ctor(Int32 size) at System.Data.RBTree1.AllocPage(Int32 size) at System.Data.RBTree`1.GetNewNode(K key) at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException) at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)
It is perfectly working on some environments.