Esempio n. 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (IsBusy)
            {
                CancelBackgroundWorker();
            }
            else
            {
                IsBusy = true;
                SetButtonText(false);

                string input = CleanupString(tbInput.Text);

                int bits = 0;
                if (!int.TryParse(input, out bits))
                {
                    WriteMessageBox("Error parsing number of bits: Try entering only numeric characters into the input TextBox.");
                }
                else if (bits < 7)
                {
                    WriteMessageBox("If you need to find prime numbers smaller than seven 7 bits, use a non-specialized calculator.");
                }
                else
                {
                    algorithmWorker                 = new ThreadedAlgorithmWorker(SearchDepth, Settings.Logging_Enabled);
                    algorithmWorker.DoWorkFunc      = algorithmWorker.DoWork_FindPrime;
                    algorithmWorker.WorkerComplete += FindPrimes_WorkerComplete;

                    ResetCancellationTokenSource();

                    algorithmWorker.StartWorker(cancelSource.Token, bits);
                }
            }
        }
Esempio n. 2
0
        public bool StartWorker(int primeBitSize)
        {
            if (!IsBusy)
            {
                IsBusy = true;

                if (cancelSource != null)
                {
                    cancelSource.Dispose();
                    cancelSource = null;
                }
                if (cancelSource == null)
                {
                    NewCancelTokenAndSource();
                }

                primeFindTimer.Reset();
                primeFindTimer.Start();
                algorithmWorker.StartWorker(cancelToken, primeBitSize);
                return(true);
            }
            return(false);
        }