Offline map package is locked after using it on Xamarin Forms (UWP)

1060
2
Jump to solution
03-01-2021 10:06 AM
ERICDUCOS
New Contributor II

Hi,

I have written a simple Xamarin Forms App with two pages.

The first page is the main page, the second one is a page with a MapView control that displays an Offline Map package. All is working good.

I can navigate between the two page in replacing the MainPage value of the Xamarin application.

The problem is the following one:

On WIndows platform, when I goes the first time on the map page and come back to the main page, the map page being no more used is supposed to be released and ressources free...BUT, if I try to move or delete locally the package (simulating for exemple an update coming from the server)...I cannot because the files are locked, whereas they are no more used (I am on the main page).

 On Android, there is no problem...I can do whatever I want with the files of the package when I am on the main page.

How can I free ressource used and kept internally by he runtime so that I can update the package from the main page !

 

Regards.

0 Kudos
1 Solution

Accepted Solutions
ERICDUCOS
New Contributor II

Hi, thanks for your reply...

When you told me to kill the object using that package, I did see how...and then I had an idea:

Before I had copied th code from sample of ESRI like that. I was initializing the Map in Initialize function called in constructor of my Page class:

MobileMapPackage package = await MobileMapPackage.OpenAsync(filepath);
await package.LoadAsync();
MyMapView.Map = package.Maps.First();

In the destructor of the page, I just forced the MyMapView.Map to null...but it was not enough.

NOW, I moved the package variable as private in my page class, and used the private variable in the destructor adding that:

MyMapView.Map = null;
package.Close();
package = null;

The Close call seem to get all the things happy...now I can deleted and replace my files 

View solution in original post

2 Replies
MichaelDavis3
Occasional Contributor III

Yep Windows does file locking whereas iOS and Android don't.  You'll most likely have to specifically kill any objects using that package before you can touch the files.

One thing I've done is to append a date stamp to my .geodatabase downloads and store the current file name in preferences.  Then when I need to update I download the new version with a new name, rebuild/refresh my ESRI stuff to point at the new database and then archive or delete the old one.

0 Kudos
ERICDUCOS
New Contributor II

Hi, thanks for your reply...

When you told me to kill the object using that package, I did see how...and then I had an idea:

Before I had copied th code from sample of ESRI like that. I was initializing the Map in Initialize function called in constructor of my Page class:

MobileMapPackage package = await MobileMapPackage.OpenAsync(filepath);
await package.LoadAsync();
MyMapView.Map = package.Maps.First();

In the destructor of the page, I just forced the MyMapView.Map to null...but it was not enough.

NOW, I moved the package variable as private in my page class, and used the private variable in the destructor adding that:

MyMapView.Map = null;
package.Close();
package = null;

The Close call seem to get all the things happy...now I can deleted and replace my files