private async void LoadComic(IImageManager imageManager) { CacheFactory.DestoryCacheManager(_cacheManager); _imageManager = imageManager; if (this.IsComicLoaded()) { var storageLocation = _storageManager.GetStorageLocation(imageManager.Location); _cacheManager = CacheFactory.GetCacheManager(imageManager, storageLocation.Index, CacheCallback); await Dispatcher.InvokeAsync(() => { if (storageLocation.Rotated) { if (!(_viewManager.IsDisplayInPortraitMode())) { _viewManager.RotateDisplay(true); } } else { if (_viewManager.IsDisplayInPortraitMode()) { _viewManager.RotateDisplay(false); } } // Use the Image manager's initial index if it is set, otherwise use the StorageLocation's Index int index = imageManager.InitialIndex >= 0 ? imageManager.InitialIndex : storageLocation.Index; LoadImage(() => _cacheManager.GetItem(index)); DisplayComicDetails(_imageManager); }, System.Windows.Threading.DispatcherPriority.Background); } else { // Reset image LoadImage(() => null); //TODO: find a better message or not show a message at all. imageManager is null here //DisplayMessage(string.Format("'{0}' does not contain any images", imageManager.DisplayName)); } }