Hi,
There are around 50k records in a shapefile feature class. I am using following code block to modify the features.
private async Task UpdateData(FeatureLayer layer)
{
using (FeatureClass oInFC = layer.GetFeatureClass())
{
var featCursor = oInFC.Search(null, false);
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
while (featCursor.MoveNext())
{
var feat = featCursor.Current;
//Modify feature attributes
feat.Store();
context.Invalidate(feat);
}
}, oInFC);
try
{
var result = await editOperation.ExecuteAsync();
if (!result)
{
throw new Exception(editOperation.ErrorMessage);
}
}
catch(Exception ex)
{
//Handle Exception
}
}
}
I see a protected memory access violation exception randomly. Any idea why this might be occurring ?
Thanks,
Sai
Solved! Go to Solution.
Hi Sai,
ArcGIS Pro SDK recommends use of 'using' when you work with database objects. It will manage object life cycle.
Try change your code like this:
using (var feat = featCursor.Current)
{
//Modify feature attributes
feat.Store();
context.Invalidate(feat);
}
Hi Sai,
ArcGIS Pro SDK recommends use of 'using' when you work with database objects. It will manage object life cycle.
Try change your code like this:
using (var feat = featCursor.Current)
{
//Modify feature attributes
feat.Store();
context.Invalidate(feat);
}
Thanks for spotting the issue @Gintautas_Kmieliauskas. I missed that.
I changed the code to a using block and it worked.
Cheers!