Hi all,
I was hoping to get some advice regarding feature layers and Geodatabase objects.
In our software we have a Map which loads and then displays feature layers. We need a process for updating the data behind the feature layers while the program is running (a Geodatabase file). We do this by clearing the OperationalLayers of the Map object. This removes the feature layers.
The problem we have is that clearing the OperationalLayers does not remove the file lock on the Geodatabase file immediately. Instead, this can take quite some time, normally until the next Garbage Collector (GC) run.
We have tried forcing a GC collection; however, this is not guaranteed to clear the file lock before we need to update the file.
We have also attempted using a Geodatabase.Close() method call, but this does not seem to have any effect beyond that of the OperationalLayers.Clear() method.
It would be great if anyone knows of a way we can clear the OperationalLayers (feature layers) and remove the file lock immediately (or awaitable) from the Geodatabase file. Currently our solution is to force a GC collection and run Thread.Sleep() for a second, which is not ideal.
In our code, feature layers are added directly to the Map’s OperationalLayers. The Geodatabase object is a local variable and should be out of scope after the feature layer data is loaded and before being passed to the Map’s OperationalLayers.
Code:
public Map Map
private void RemoveAllFeatureLayers()
{
Map.OperationalLayers.Clear();
GC.Collect();
Thread.Sleep(1000);
}
Using the following:
- Esri.ArcGISRuntime - Nuget package v100.15.0
- Esri.ArcGISRuntime.UWP - Nuget package v100.15.0
- C# - UWP .Net Standard 2.0
- MVVM model (so ideally, we want to avoid solutions that make use of a view's code behind)