Example #1
0
        private void FindPrimes(object data)
        {
            if (data is PrimeRange)
            {
                PrimeRange range        = (PrimeRange)data;
                decimal    width        = range.To - range.From;
                decimal    currprogress = 0;
                for (decimal value = range.From; value <= range.To; value++)
                {
                    if (stopping)
                    {
                        return;
                    }
                    //Update progress bar
                    currprogress = value - nudFrom.Value;
                    double progress = (double)currprogress / (double)width;
                    if (InvokeRequired)
                    {
                        try
                        {
                            Invoke(new delVoidInt(UpdateProgress), (int)(progress * 100));
                        }
                        catch (ObjectDisposedException)
                        {
                            System.Diagnostics.Trace.Write("Attempt to access form, when form is dead.  Like, doornail.  Marilyn Monroe. Michael Jackson.");
                        }
                    }

                    if (isPrime(value))
                    {
                        if (InvokeRequired)
                        {
                            try
                            {
                                Invoke(new delVoidDecimal(AddPrime), value);
                            }
                            catch (ObjectDisposedException)
                            {
                                System.Diagnostics.Trace.Write("Attempt to access form, when form is dead.  Like, doornail.  Marilyn Monroe. Michael Jackson.");
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private void btnGo_Click(object sender, EventArgs e)
 {
     switch (btnGo.Text)
     {
         case "Go":
             btnGo.Text = "Stop";
             stopping = false;
             this.Refresh();
             lbResults.Items.Clear();
             PrimeRange pr = new PrimeRange(nudFrom.Value, nudTo.Value);
             working = new Thread(new ParameterizedThreadStart(FindPrimes));
             working.Start(pr);
             break;
         case "Stop":
             btnGo.Text = "Go";
             stopping = true;
             break;
     }
 }
Example #3
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            switch (btnGo.Text)
            {
            case "Go":
                btnGo.Text = "Stop";
                stopping   = false;
                this.Refresh();
                lbResults.Items.Clear();
                PrimeRange pr = new PrimeRange(nudFrom.Value, nudTo.Value);
                working = new Thread(new ParameterizedThreadStart(FindPrimes));
                working.Start(pr);
                break;

            case "Stop":
                btnGo.Text = "Go";
                stopping   = true;
                break;
            }
        }