/// <summary> /// Performs prime number search /// </summary> private async void Start() { using (StartCommand.RunWithDisabled()) using (_cancellationTokenSource = new CancellationTokenSource()) { var progress = new ProgressFilterProxy(new Progress <double>(d => Progress = (int)(d * 100))); try { var primes = await _sieveOfEratosthenesCalculator.MakeSieveAsync((int)NumberRange, progress, _cancellationTokenSource.Token); Progress = 100; ResultText = $"Znaleziono {primes.Count} liczb pierwszych"; PrimeNumbers.Clear(); PrimeNumbers.AddRange(primes, ObservableCollectionEx <int> .ECollectionChangeNotificationMode.Reset); } catch (OperationCanceledException ex) when(ex.CancellationToken == _cancellationTokenSource.Token) { ResultText = "Operacja zatrzymana"; PrimeNumbers.Clear(); } finally { _cancellationTokenSource = null; } } }