private async Task Render() { if (!_rendering && !_stop) { _rendering = true; // Render camera preview frame to screen _writeableBitmapRenderer.Source = _cameraPreviewImageSource; _writeableBitmapRenderer.WriteableBitmap = _writeableBitmap; await _writeableBitmapRenderer.RenderAsync(); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.High, () => { _writeableBitmap.Invalidate(); }); // Write camera preview frame to file if capturing if (_capturing) { if (_sequenceIndex < 20) { _jpegRenderer.Source = _cameraPreviewImageSource; IBuffer jpg = await _jpegRenderer.RenderAsync(); await Save(jpg, _sequenceIndex ++); } else { StartStopCapture(); } } _rendering = false; } if (_stop) { _capturing = false; _cameraPreviewImageSource.Dispose(); _writeableBitmapRenderer.Dispose(); _jpegRenderer.Dispose(); } }