Esempio n. 1
0
        private void OnFind(object sender, RoutedEventArgs e)
        {
            // Disable the button and clear previous results.
            FindButton.IsEnabled   = false;
            CancelButton.IsEnabled = true;
            PrimeListBox.Items.Clear();

            // Get the search range.
            int from, to;

            if (!int.TryParse(FromTextBox.Text, out from))
            {
                MessageBox.Show("Invalid From value.");
                return;
            }

            if (!int.TryParse(ToTextBox.Text, out to))
            {
                MessageBox.Show("Invalid To value.");
                return;
            }

            // Start the search for primes on another thread.
            var input = new FindPrimesInput(from, to);

            _primeBackgroundWorker.RunWorkerAsync(input);
        }
Esempio n. 2
0
        private void cmdFind_Click(object sender, RoutedEventArgs e)
        {
            // Disable the button and clear previous results.
            cmdFind.IsEnabled   = false;
            cmdCancel.IsEnabled = true;
            lstPrimes.Items.Clear();

            // Get the search range.
            int from, to;

            if (!Int32.TryParse(txtFrom.Text, out from))
            {
                MessageBox.Show("Invalid From value.");
                return;
            }
            if (!Int32.TryParse(txtTo.Text, out to))
            {
                MessageBox.Show("Invalid To value.");
                return;
            }

            // Start the search for primes on another thread.
            FindPrimesInput input = new FindPrimesInput(from, to);

            backgroundWorker.RunWorkerAsync(input);
        }
Esempio n. 3
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the input values.
            FindPrimesInput input = (FindPrimesInput)e.Argument;

            // Start the search for primes and wait.
            int[] primes = Worker.FindPrimes(input.From, input.To, backgroundWorker);

            if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            // Return the result.
            e.Result = primes;
        }
        private void cmdFind_Click(object sender, RoutedEventArgs e)
        {
            // Disable the button and clear previous results.
            cmdFind.IsEnabled = false;
            cmdCancel.IsEnabled = true;
            lstPrimes.Items.Clear();            

            // Get the search range.
            int from, to;
            if (!Int32.TryParse(txtFrom.Text, out from))
            {
                MessageBox.Show("Invalid From value.");
                return;
            }
            if (!Int32.TryParse(txtTo.Text, out to))
            {
                MessageBox.Show("Invalid To value.");
                return;
            }

            // Start the search for primes on another thread.
            FindPrimesInput input = new FindPrimesInput(from, to);
            backgroundWorker.RunWorkerAsync(input);
        }