H
hangar18
Hi,
I'm looping through some folders and files and adding them to a
datatable.
This gives me the following OutOfMemoryException at times.
Error Exception of type 'System.OutOfMemoryException' was thrown.
----------- Error at System.Data.RBTree`1.TreePage..ctor(Int32 size)
at System.Data.RBTree`1.AllocPage(Int32 size)
at System.Data.RBTree`1.GetNewNode(K key)
at System.Data.RBTree`1.Insert(K item)
at System.Data.Index.InitRecords(IFilter filter)
at System.Data.Index..ctor(DataTable table, Int32[] ndexDesc,
IndexField[] indexFields, DataViewRowState recordStates, IFilter
rowFilter)
at System.Data.DataTable.GetIndex(IndexField[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataTable.LoadDataRow(Object[] values, LoadOption
loadOption)
The code is as follows. THis code is executed for each file that is
found. We are basically calulating the extensions and the size of the
files wth similar extensions. The number of files are huge crossing
1,00,000 easily
private void AddExtInfo(FileInfo objFileInfo, string strRootPath)
{
string strExpr = "Ext = '" + objFileInfo.Extension.Replace("'","''") +
"'";
DataRow[] drResult;
drResult = dtDirInfoExt.Select(strExpr);
if (drResult.Length > 0)
{
object[] newRow1 = new object[4];
newRow1[0] = drResult[0][0];
newRow1[1] = drResult[0][1];
newRow1[2] = Convert.ToInt32(drResult[0][2]) + 1;
newRow1[3] = Convert.ToDouble(drResult[0][3]) +
objFileInfo.Length;
dtDirInfoExt.BeginLoadData();
dtDirInfoExt.LoadDataRow(newRow1,
LoadOption.OverwriteChanges);
dtDirInfoExt.EndLoadData();
}
else
{
newRow = dtDirInfoExt.NewRow();
newRow[0] = strRootPath;
newRow[1] = objFileInfo.Extension;
newRow[2] = 1;
newRow[3] = objFileInfo.Length;
dtDirInfoExt.Rows.Add(newRow);
}
any help will be highly appreciated..
Soni
I'm looping through some folders and files and adding them to a
datatable.
This gives me the following OutOfMemoryException at times.
Error Exception of type 'System.OutOfMemoryException' was thrown.
----------- Error at System.Data.RBTree`1.TreePage..ctor(Int32 size)
at System.Data.RBTree`1.AllocPage(Int32 size)
at System.Data.RBTree`1.GetNewNode(K key)
at System.Data.RBTree`1.Insert(K item)
at System.Data.Index.InitRecords(IFilter filter)
at System.Data.Index..ctor(DataTable table, Int32[] ndexDesc,
IndexField[] indexFields, DataViewRowState recordStates, IFilter
rowFilter)
at System.Data.DataTable.GetIndex(IndexField[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)
at System.Data.DataTable.LoadDataRow(Object[] values, LoadOption
loadOption)
The code is as follows. THis code is executed for each file that is
found. We are basically calulating the extensions and the size of the
files wth similar extensions. The number of files are huge crossing
1,00,000 easily
private void AddExtInfo(FileInfo objFileInfo, string strRootPath)
{
string strExpr = "Ext = '" + objFileInfo.Extension.Replace("'","''") +
"'";
DataRow[] drResult;
drResult = dtDirInfoExt.Select(strExpr);
if (drResult.Length > 0)
{
object[] newRow1 = new object[4];
newRow1[0] = drResult[0][0];
newRow1[1] = drResult[0][1];
newRow1[2] = Convert.ToInt32(drResult[0][2]) + 1;
newRow1[3] = Convert.ToDouble(drResult[0][3]) +
objFileInfo.Length;
dtDirInfoExt.BeginLoadData();
dtDirInfoExt.LoadDataRow(newRow1,
LoadOption.OverwriteChanges);
dtDirInfoExt.EndLoadData();
}
else
{
newRow = dtDirInfoExt.NewRow();
newRow[0] = strRootPath;
newRow[1] = objFileInfo.Extension;
newRow[2] = 1;
newRow[3] = objFileInfo.Length;
dtDirInfoExt.Rows.Add(newRow);
}
any help will be highly appreciated..
Soni