async Task SaveThumbnail(CanvasBitmap thumbnail, string suffix) { using (var stream = await outputFolder.OpenStreamForWriteAsync(exampleDefinition.ThumbnailFilename(suffix), CreationCollisionOption.ReplaceExisting)) { await thumbnail.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png); } }
async Task SaveThumbnail(CanvasBitmap thumbnail, string suffix) { // Dispatch the file open operation back onto the UI thread (some machines have issues doing this elsewhere). var streamSource = new TaskCompletionSource <Stream>(); await uiThreadDispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { try { var stream = await outputFolder.OpenStreamForWriteAsync(exampleDefinition.ThumbnailFilename(suffix), CreationCollisionOption.ReplaceExisting); streamSource.SetResult(stream); } catch (Exception e) { streamSource.SetException(e); } }); // Save the bitmap. using (var stream = await streamSource.Task) { await thumbnail.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png); } }