/// <summary> /// Place images received from the REST service in the proper place in the active tile cube, and save them to /// the cache. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void TileServerRequestCompleted(object sender, DownloadDataCompletedEventArgs e) { pendingRequestCount--; TileInformation requestInformation = (TileInformation)e.UserState; // Do not handle the event if the request was cancelled if (requestInformation.IsRequestCancelled) { requestInformation.MarkImageRequestCancelled(); if (pendingRequestCount == 0) { MoveToNextPhase(); } return; } bool imageAvailable = e.Error == null ? true : false; // Clean the old image, if any requestInformation.Dispose(true); try { if (imageAvailable == true) { SetTileImage(e, requestInformation); } } catch (Exception) { imageAvailable = false; Console.WriteLine("image not available Error exception"); } if (imageAvailable == false) { Console.WriteLine("image not available bad key?"); requestInformation.Image = unavailableImage; } requestInformation.MarkImageRequestCompleted(); // If all asynchronous calls returned, we can move to the next phase if (pendingRequestCount == 0) { MoveToNextPhase(); } }
/// <summary> /// Cancels all currently ongoing tile image requests, and disposes of all current tile images. /// </summary> private void CancelActiveRequestsAndResetImages() { for (int xIndex = 0; xIndex < ActiveTilePlaneSize; xIndex++) { for (int yIndex = 0; yIndex < ActiveTilePlaneSize; yIndex++) { TileInformation cellInformation = activeTilePlane[xIndex, yIndex]; if (cellInformation != null) { cellInformation.Dispose(); } } } }