Windows Mobile 3.1 - mobileCache IO error when used with WinForms map control

2211
0
10-15-2012 11:14 AM
StevenSchuldt
New Contributor
I'm running into an issue with the MobileCache object in ArcGIS for Windows 3.1.  Basically it seems once you've added your mobile cache to the map control to display the data, you can't delete it any longer even if you've removed the cache layers from from map control.  You'll receive a System.IO error saying the mobile cache is in use by another process.

I created a test project where I just have a Map control, a MobileServiceConnection, and a MobileCache.

If I create and populate cache but don't add the data to the map, I can delete it after I call the Close method on the cache.  If I add the cache to the MapLayers collection of the map control, no matter what I do I can't seem to delete the cache any longer - even if I've removed cache from the MapLayers of the map control.

I need to Delete the cache because the user can switch projects in our application which then downloads a mobile cache from a different URL. 

Any suggestions are appreciated.

   
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ESRI.ArcGIS.Mobile.FeatureCaching.Synchronization;

namespace TestMobileCache {
 public partial class Form1 : Form {
  public Form1() {
   InitializeComponent();
  }

  /// <summary>
  /// Create the mobile cache and populate it with data
  /// </summary>
  private void buttonCreateMobileCache_Click(object sender, EventArgs e) {

   //setup the mobile cache and mobile service connection
   this.mobileCache1.StoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CacheTest");
   this.mobileServiceConnection1.WebClientProtocolType = ESRI.ArcGIS.Mobile.FeatureCaching.WebClientProtocolType.BinaryWebService;
   this.mobileServiceConnection1.Url = "http://1540sr-gis/arcgis/services/Test/WetlandsFieldSurveyDirect/MapServer/MobileServer";
   this.mobileServiceConnection1.CreateCache(this.mobileCache1);
   this.mobileCache1.Open();


   //download data for all layers 
   MobileCacheSyncAgent syncAgenct = new MobileCacheSyncAgent(this.mobileCache1);
   foreach(var fs in mobileCache1.FeatureSources) {
    var fsa = new FeatureSyncAgent(fs);
    fsa.MapDocumentConnection = this.mobileServiceConnection1;
    fsa.SynchronizationDirection = SyncDirection.DownloadOnly;
    syncAgenct.FeatureSyncAgents.Add(fsa);
    fsa.Synchronize();
   }

  }

  /// <summary>
  /// Attempt to delete the cache
  /// </summary>
  private void buttonDeleteCache_Click(object sender, EventArgs e) {

   //Remove the mobile cache layers from the map control
   if (this.map1.MapLayers.Count > 0) {
    this.map1.MapLayers.Remove(this.mobileCache1);
   }

   //Close the cache and attempt to delete it
   this.mobileCache1.Close();
   this.mobileCache1.DeleteCache();
  }

  /// <summary>
  /// Add the map cache layers to the map control
  /// </summary>
  private void buttonAddLayerToMap_Click(object sender, EventArgs e) {
   this.map1.MapLayers.Add(this.mobileCache1);
  }
 }
}

0 Kudos
0 Replies