lock files remains for local geodatabase in WPF App

5586
8
10-20-2014 01:33 PM
MyronChew
New Contributor

After I used OpenAsync on a local geodatabase, it created these two lock files: .geodatabase-wal,.geodatabase-shm after I added some layers to the MapView.   The lock files remain even I removed all its layers or perform GC.Collect.  Is there a way to close the opened geodatabase without closing the application?

8 Replies
dotMorten_esri
Esri Notable Contributor

Did you also remove all references to the table, geodatabase and waited for pending finalizers?

0 Kudos
MyronChew
New Contributor

Hi Nielsen

             
Thanks for your quick reply.

The following is my test project I pulled out from our
development.  Unloading will not release the map lock files. 

My xaml markup and code are as followed:

<Window

      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

      xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" xmlns:Custom="http://infragistics.com/DockManager" x:Class="ArcGISRunTimeTest.MainWindow"

      Title="MainWindow" Height="350" Width="525">

   <Grid>

       <esri:MapView x:Name="mapView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MouseDown="MapView_MouseDown" MapViewTapped="MapView_MapViewTapped" MouseDoubleClick="MapView_MouseDoubleClick" KeyDown="MapView_KeyDown" Margin="0,63,0.4,0.4" ExtentChanged="mapView_ExtentChanged" MouseMove="mapView_MouseMove" PreviewMouseDoubleClick="mapView_PreviewMouseDoubleClick">

           <esri:Map>

              

                <esri:GraphicsLayer x:Name="graphicsLayer"
/>

           </esri:Map>

       </esri:MapView>

       <Button Content="Button" HorizontalAlignment="Left" Height="28" Margin="49,8,0,0" VerticalAlignment="Top" Width="70" Click="Button_Click"/>

       <Button Content="Button" HorizontalAlignment="Left" Height="28" Margin="183,8,0,0" VerticalAlignment="Top" Width="79" Click="Button_Click_1"/>

       <TextBox x:Name="textbox1" Height="38" Margin="323,8,35.4,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>

       <Button Content="LoadMap" HorizontalAlignment="Left" Margin="49,63,0,0" VerticalAlignment="Top" Width="75" Click="Load_Click"/>

       <Button Content="unLoadMap" HorizontalAlignment="Left" Margin="183,63,0,0" VerticalAlignment="Top" Width="79" Click="Unload_Click" RenderTransformOrigin="1.987,0.454"/>

   </Grid>

</Window>

private async void Load_Click(object sender, RoutedEventArgs e)

      
{

           if
(!mapView.IsInitialized)
return;

          
mapView.Map =
new Map()

                        
  {

                              
InitialViewpoint =
new Viewpoint(new Envelope(-13054165, 3850112, -13027133, 3863559, SpatialReferences.WebMercator))

                          
};

          
mapView.Map.SpatialReference =
SpatialReferences.WebMercator;

           Geodatabase gdb = await Geodatabase.OpenAsync(@"C:\Temp\H2OTEST.IWDB\Map\map.geodatabase");

           GeodatabaseFeatureTable gftable = gdb.FeatureTables.FirstOrDefault(m =>
m.Name.ToUpper() ==
"JUNCTION");

           FeatureLayer myFeatureLayer = new Esri.ArcGISRuntime.Layers.FeatureLayer(gftable);

          
mapView.Map.Layers.Add(myFeatureLayer);

          

            gftable
= gdb.FeatureTables.FirstOrDefault(m => m.Name.ToUpper() ==
"PIPE");

          
mapView.SetViewAsync(myFeatureLayer.FullExtent);

          
myFeatureLayer =
new Esri.ArcGISRuntime.Layers.FeatureLayer(gftable);

          
mapView.Map.Layers.Add(myFeatureLayer);

      
}

       private void Unload_Click(object sender, RoutedEventArgs e)

      
{

 
         mapView.Map.Layers.Clear();

          
System.
GC.Collect();

           GC.WaitForPendingFinalizers();

          

        }

0 Kudos
ArtemHmara
New Contributor

Did you find out solution for this issue?

0 Kudos
ReedHunter
New Contributor III

I ran into this problem, and the WaitForPendingFinalizers clue helped me to solve this.  I have a .Net app for downloading a geodatabase, acquiring and writing to the geodatabase some attributes from an external sql server database, syncing edits back if necessary to the feature service, and then zipping the offline geodatabase.  The geodatabase openasync however would hold a lock on the .geodatabase file, preventing the zip from working.  The solution was to structure my program this way ...

        static void Main()

        {

            var gdbPath = "";

            Task.Run(async () =>

            {

                //omitting code for downloading geodatabase asynchronously, and other operations on the file

            }).Wait(); 

            GC.Collect(); 

            GC.WaitForPendingFinalizers();

          //code to zip the geodatabase

        }

Hope this helps anyone else who comes across this problem.

0 Kudos
PhilScovis
New Contributor III

I've had this problem too; This thread claims that it is a known bug.  

In my case, I'm trying to re-create a .geodatabase from the server.  I can remove the existing layer from the map view, but there's no way to dispose it. 

My workaround was to use a new filename for the new file.  I check for old files when the application starts, and try to delete them.  This is not ideal, because the old file will remain in the filesystem until the application restarts.  

0 Kudos
AnttiKajanus1
Occasional Contributor III

You can use Geodatabase.Close Method  to close the geodatabase so all the locks are released.

PhilScovis
New Contributor III

That worked; thank you!

0 Kudos
PhilScovis
New Contributor III

Is there an equivalent for a .tpk file that is being held open by a Tiled Layer?

0 Kudos