void LoadThread() { using (var pool = new MonoTouch.Foundation.NSAutoreleasePool()) { while (_continueWorkingInBackground) { TileCollectionItem q = null; lock (_loadingTiles) { q = _loadingTiles.GetHighestPriority(); } if (q == null) { _wakeupLoader.WaitOne(TimeSpan.FromSeconds(5)); } else { var req = q.Name; try { var filename = GetTilePath(req); using (var image = UIImage.FromFileUncached(filename)) { if (image != null) { var data = TextureData.FromUIImage(image); lock (_loadedTiles) { _loadedTiles[req] = data; } } else { Console.WriteLine("! Failed to load " + req); throw new Exception(); } } } catch (Exception) { // // If there was an error loading the tile, then it // must be bad. Redownload it. // lock (_onDiskTiles) { _onDiskTiles.Remove(req); } } finally { lock (_loadingTiles) { _loadingTiles.Remove(req); } } } } } }
void DownloadThread() { using (var pool = new MonoTouch.Foundation.NSAutoreleasePool()) { while (_continueWorkingInBackground) { TileCollectionItem q; lock (_downloadingTiles) { q = _downloadingTiles.GetHighestPriority(); } if (q == null) { _wakeupDownloader.WaitOne(TimeSpan.FromSeconds(5)); } else { var req = q.Name; var url = _source.GetTileUrl(req); var filename = GetTilePath(req); var tempFile = Path.GetTempFileName(); var downloadedSuccessfully = Http.Download(url, tempFile); if (downloadedSuccessfully) { try { File.Move(tempFile, filename); lock (_onDiskTiles) { _onDiskTiles[req] = true; } lock (_downloadingTiles) { _downloadingTiles.Remove(req); } } catch (Exception) { } } else { // Download failed, let's chill out for a bit _wakeupDownloader.WaitOne(TimeSpan.FromSeconds(5)); } } } } }