private async void PermutateHashes_Click()

in HashCalculator/Views/PermutateHash.xaml.cs [165:199]


        private async void PermutateHashes_Click(object sender, RoutedEventArgs e)
        {
            bool found = false;
            ResultHashes.Items.Clear();
            try
            {
                Worker.ValidateIsHash((string)ListOfAlgorithms.SelectedItem, ExpectedResultHash.Text.Trim());

                cts = new CancellationTokenSource();
                found = await CheckAndUpdateAsync(cts.Token);
            }
            catch (OperationCanceledException)
            {
                ResultHashes.Items.Add("Computation cancelled.");
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(ex.Message))
                {
                    ResultHashes.Items.Add("Computation failed.");
                }
                else
                {
                    ResultHashes.Items.Add(ex.Message);
                }
            }
            finally
            {
                // Set the CancellationTokenSource to null when the computation is complete.  
                cts = null;

                if (!found)
                    ResultHashes.Items.Add("No order of the provided hashes resulted in the expected hash value.");
            }
        }