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 = MultithreadingWorker.Worker.FindPrimes(input.From, input.To, backgroundWorker);

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

            // Paste the list of primes together into one long string.
            StringBuilder sb = new StringBuilder();

            foreach (int prime in primes)
            {
                sb.Append(prime.ToString());
                sb.Append("  ");
            }

            // Return the result.
            e.Result = sb.ToString();
        }
        private void cmdFind_Click(object sender, EventArgs e)
        {
            // Disable the button.
            cmdFind.Enabled  = false;
            statusPanel.Text = "";

            // 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);
        }
        private void cmdFind_Click(object sender, EventArgs e)
        {
            // Disable the button.
            cmdFind.Enabled = false;          
            statusPanel.Text = "";

            // 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);
        }