private void ApplyFilter(FilterParams p) { IsBusy = true; IsPreview = true; _cancellationTokenSource?.Cancel(); _cancellationTokenSource = new CancellationTokenSource(); var ct = _cancellationTokenSource.Token; Task.Run(async() => { if (_smallImage != null) { DisplayedImage = await _imageFilter.Filter(_smallImage, p, ct); // small delay so it doesnt give "epilepsy" when displaying // constantly altering smallImage and Image await Task.Delay(100, ct); } ct.ThrowIfCancellationRequested(); //no need to catch this or other ct exceptions in this case var image = await _imageFilter.Filter(_originalImage, p, ct); DisplayedImage = image; IsBusy = false; IsPreview = false; }, ct); }