I have an offline device running a WPF app using VectorTileCache to add ArcGISVectorTiledLayer to the app's map. VectorTileCache loads a .vtpk file from the device's disk.
I have built capability to download a new version of the .vtpk file from a remote source and I would like to reload the ArcGISVectorTiledLayer when the new file is ready.
When I try to replace the old vtpk with the new one, I get an error that the file is in use:
System.IO.IOException: 'The process cannot access the file 'C:\temp\GeocacheKystVector.vtpk' because it is being used by another process.'
The ArcGISVectorTiledLayer that refers the vtpk is an item in Basemap.BaseLayers. I remove the item, run GC, but still get that IOException.
How do I unload the package?
Hi @ViktorSafar, could you please provide the code used to do this?
Hi @AndyWeis
While attempting to make a PoC about this, it turned out I was overcomplicating things.
What I was doing:
The IO Exception was of course happening in step 3 as the file was being used by the application
I have now changed it to just directly copy the TEMP file into the current VTPK file
File.Copy(_newPackageFile, _packageFile, overwrite: true);
and am getting no exceptions.
However, I am uncertain if this works as intended - aka the map is updated with the new package, as this is hard to check (basemap layers are big 🙂 ).
To test it, I have been using 2 VTPK packages, each containing a different map (visually different):
I load package1 (mymap.vtpk) into the map on startup, then on button click I copy package2 file into package1 file. No error. The only thing I notice is that the map stops rendering details:
I realize this might not be the best way to test it due to the packages containing different maps.
What would be the recommended way to update a local package (that is loaded into the application) while the application is running? Could it be as simple as this?
File.Copy(_newPackageFile, _packageFile, overwrite: true);
Map.Basemap.BaseLayers.First().RetryLoadAsync(); // find the appropriate base layer