Rash M

Rash M

  • NA
  • 1
  • 822

How to improve the performance of c# program

Jul 3 2015 5:19 AM
I am trying to to extract sdf file from geodatabase.As the new sdf file created ,the memory usage by program increases.To overcome this issue I have tried to reaseing connection for sdf file and also tried to release resources by using GC.Collect() method but still the problem persist.
 
 

/// <summary>
/// Get feature data from geodatabase file
/// </summary>
/// <param name="dictionaryProperty">dictionaryProperty-Schema of table</param>
/// <param name="table"></param>
/// <param name="sdffilepath"></param>
static void GetFeatureData(Geodatabase geodatabase, string tablename, string sdffilepath)
{
int filecount = 1; ;
string query="select * from "+tablename;
IConnection con = OpenFDOSDFConnection(sdffilepath);

foreach (Row row in geodatabase.ExecuteSQL(query))
{
IInsert insertCommand = (IInsert)con.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Insert);
insertCommand.SetFeatureClassName(tablename);
for (int nFieldNumber = 0; nFieldNumber < row.FieldInformation.Count; nFieldNumber++)
{
string fieldName=row.FieldInformation.GetFieldName(nFieldNumber);
switch (row.FieldInformation.GetFieldType(nFieldNumber))
{
case FieldType.Integer:
if (row.IsNull(fieldName))
{
insertCommand.PropertyValues.Add(new PropertyValue(fieldName, null));
}
else
{
insertCommand.PropertyValues.Add(new PropertyValue(fieldName, new Int64Value(row.GetInteger(fieldName))));
}
break;
case FieldType.OID:
if (row.IsNull(fieldName))
{
insertCommand.PropertyValues.Add(new PropertyValue(fieldName, null));
}
else
{
insertCommand.PropertyValues.Add(new PropertyValue(fieldName, new Int64Value(Convert.ToInt64(row.GetOID()))));
}
break;
case FieldType.Geometry:
if(!row.IsNull(fieldName))
{
switch (row.GetGeometry().geometryType.ToString())
{
case "Point":
PointShapeBuffer pointGeometry = row.GetGeometry();
FgfGeometryFactory factory = new FgfGeometryFactory();
DirectPositionCollection pcollection = new DirectPositionCollection();
IDirectPosition iPos = factory.CreatePositionXY(pointGeometry.point.x,pointGeometry.point.y);
IPoint pt = factory.CreatePoint(iPos);
GeometryValue geometryValue = new GeometryValue(factory.GetFgf(pt));
insertCommand.PropertyValues.Add(new PropertyValue("Geometry", geometryValue));
break;
}
}
else
{
insertCommand.PropertyValues.Add(new PropertyValue("Geometry", null));
}
break;
//code contains cases for other datatype
}
break;
//code contains cases for other datatype
}
insertCommand.Execute();
insertCommand.Dispose();
}
}