<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I free/unload local tile cache file? in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1256447#M11674</link>
    <description>&lt;P&gt;I have an offline device running a WPF app using VectorTileCache to add&amp;nbsp;ArcGISVectorTiledLayer to the app's map.&amp;nbsp;VectorTileCache loads a .vtpk file from the device's disk.&lt;/P&gt;&lt;P&gt;I have built capability to download a new version of the .vtpk file from a remote source and I would like to reload the&amp;nbsp;ArcGISVectorTiledLayer when the new file is ready.&lt;/P&gt;&lt;P&gt;When I try to replace the old vtpk with the new one, I get an error that the file is in use:&lt;/P&gt;&lt;P&gt;System.IO.IOException: 'The process cannot access the file 'C:\temp\GeocacheKystVector.vtpk' because it is being used by another process.'&lt;/P&gt;&lt;P&gt;The&amp;nbsp;ArcGISVectorTiledLayer that refers the vtpk is an item in&amp;nbsp;Basemap.BaseLayers. I remove the item, run GC, but still get that&amp;nbsp;IOException.&lt;/P&gt;&lt;P&gt;How do I unload the package?&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2023 11:46:54 GMT</pubDate>
    <dc:creator>ViktorSafar</dc:creator>
    <dc:date>2023-02-09T11:46:54Z</dc:date>
    <item>
      <title>How do I free/unload local tile cache file?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1256447#M11674</link>
      <description>&lt;P&gt;I have an offline device running a WPF app using VectorTileCache to add&amp;nbsp;ArcGISVectorTiledLayer to the app's map.&amp;nbsp;VectorTileCache loads a .vtpk file from the device's disk.&lt;/P&gt;&lt;P&gt;I have built capability to download a new version of the .vtpk file from a remote source and I would like to reload the&amp;nbsp;ArcGISVectorTiledLayer when the new file is ready.&lt;/P&gt;&lt;P&gt;When I try to replace the old vtpk with the new one, I get an error that the file is in use:&lt;/P&gt;&lt;P&gt;System.IO.IOException: 'The process cannot access the file 'C:\temp\GeocacheKystVector.vtpk' because it is being used by another process.'&lt;/P&gt;&lt;P&gt;The&amp;nbsp;ArcGISVectorTiledLayer that refers the vtpk is an item in&amp;nbsp;Basemap.BaseLayers. I remove the item, run GC, but still get that&amp;nbsp;IOException.&lt;/P&gt;&lt;P&gt;How do I unload the package?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 11:46:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1256447#M11674</guid>
      <dc:creator>ViktorSafar</dc:creator>
      <dc:date>2023-02-09T11:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I free/unload local tile cache file?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1259629#M11701</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607319"&gt;@ViktorSafar&lt;/a&gt;, could you please provide the code used to do this?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2023 04:30:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1259629#M11701</guid>
      <dc:creator>AndyWeis</dc:creator>
      <dc:date>2023-02-18T04:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I free/unload local tile cache file?</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1268949#M11747</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/522293"&gt;@AndyWeis&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While attempting to make a PoC about this, it turned out I was overcomplicating things.&lt;/P&gt;&lt;P&gt;What I was doing:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;load a&amp;nbsp;VTPK file (eg. mymap.vtpk)&lt;/LI&gt;&lt;LI&gt;download new package to TEMP file&lt;/LI&gt;&lt;LI&gt;delete current VTPK file (mymap.vtpk)&lt;/LI&gt;&lt;LI&gt;move TEMP file to&amp;nbsp;mymap.vtpk&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The IO Exception was of course happening in step 3 as the file was being used by the application&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have now changed it to just directly copy the TEMP file into the current VTPK file&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;File.Copy(_newPackageFile, _packageFile, overwrite: true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and am getting no exceptions.&lt;/P&gt;&lt;P&gt;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 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ).&lt;/P&gt;&lt;P&gt;To test it, I have been using 2 VTPK packages, each containing a different map (visually different):&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;mymap.vtpk (contains a coastal map of Norway)&lt;/LI&gt;&lt;LI&gt;greytone.vtpk&amp;nbsp;(contains a grey tone map of Norway)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ViktorSafar_0-1679060791553.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/65562i658C330947B03077/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ViktorSafar_0-1679060791553.png" alt="ViktorSafar_0-1679060791553.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I realize this might not be the best way to test it due to the packages containing different maps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;File.Copy(_newPackageFile, _packageFile, overwrite: true);
Map.Basemap.BaseLayers.First().RetryLoadAsync(); // find the appropriate base layer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 13:52:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-do-i-free-unload-local-tile-cache-file/m-p/1268949#M11747</guid>
      <dc:creator>ViktorSafar</dc:creator>
      <dc:date>2023-03-17T13:52:04Z</dc:date>
    </item>
  </channel>
</rss>

