After you've created your cache, loop through the layers you want to sync and add them to a MobileCacheSyncAgent, then you can call BeginDownloadExtent on the MobileCacheSyncAgent and it will do async downloads for you.Sorry it's not complete code - I just pulled bits and pieces to show the concepts.
//property for mobile sync agent
public MobileCacheSyncAgent SyncMaster { get; set; }
//snippet which initializes the sync agents for download
SyncMaster.SyncAgents.Clear();
SetupSyncAgents();
SyncMaster.BeginDownloadExtent(mobileCache1.GetInitialExtent(), 0, 0, DownloadExtent, Guid.NewGuid());
//procedure to setup the sync agents for downloads
private void SetupSyncAgents() {
foreach (Layer l in this.mobileCache1.Layers) {
if (l is FeatureLayer) {
var fl = (FeatureLayer)l;
FeatureLayerSyncAgent agent = new FeatureLayerSyncAgent(fl);
agent.MapDocumentConnection = this.mobileServiceConnection1;
agent.SynchronizationDirection = SyncDirection.DownloadOnly;
SyncMaster.SyncAgents.Add(agent);
}
if (l is RasterLayer) {
var rl = (RasterLayer)l;
RasterLayerSyncAgent agent = new RasterLayerSyncAgent(rl);
agent.Extent = this.map1.GetExtent();
agent.MapDocumentConnection = this.mobileServiceConnection1;
SyncMaster.SyncAgents.Add(agent);
}
}
}