private void CreateBitmapAndAddToProcessingCollection(string name) { Dispatcher.BeginInvoke((Action)(() => { var uri = new Uri(name); var image = new BitmapImage(uri); image.Freeze(); PendingImages.Add(image); _blockingCollection.Add(image); }), DispatcherPriority.Background); }
private void ProcessBitmaps(CancellationToken token) { while (!token.IsCancellationRequested) { BitmapImage image; try { image = _blockingCollection.Take(token); } catch (OperationCanceledException) { return; } FormatConvertedBitmap grayBitmapSource = ConvertToGrayscale(image); Dispatcher.BeginInvoke((Action)(() => { ProcessedImage = grayBitmapSource; PendingImages.Remove(image); })); Thread.Sleep(1000); } }