protected bool SaveCoverImages(string bookID, Stream imageStream) { var @event = new AutoResetEvent(false); bool result = false; ((Action)(() => { try { var bitmapImage = new BitmapImage(); bitmapImage.SetSource(imageStream.AsRandomAccessStream()); using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var iconImageFile = isoStorage.CreateFile(ModelExtensions.GetBookCoverPath(bookID))) { bitmapImage.SaveJpeg(iconImageFile, 300, 300, true); } using (var coverImageFile = isoStorage.CreateFile(ModelExtensions.GetBookFullCoverPath(bookID))) { bitmapImage.SaveJpeg(coverImageFile, bitmapImage.PixelWidth, bitmapImage.PixelHeight, false); } } result = true; } catch (Exception) { result = false; } finally { @event.Set(); } })).OnUIThread(); @event.WaitOne(); return result; }