Beispiel #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);
                }
            }
        }
Beispiel #2
0
 private void DisposeThreadedAlgorithmWorker()
 {
     if (algorithmWorker != null && !algorithmWorker.IsDisposed)
     {
         algorithmWorker.Dispose();
         algorithmWorker = null;
     }
 }
Beispiel #3
0
        public MainForm()
        {
            InitializeComponent();

            Log.LogFilename = Settings.LogFile_Methods;
            Log.SetLoggingPreference(Settings.Logging_Enabled);

            tbInput.Text       = "512";
            tbSearchDepth.Text = DefaultSearchDepth.ToString();

            algorithmWorker = null;
            //algorithmWorker = new ThreadedAlgorithmWorker(SearchDepth, Settings.Logging_Enabled);
        }
        public ConsoleWorker(bool loggingEnabled)
        {
            errors  = new Queue <Exception>();
            primes  = new Queue <BigInteger>();
            results = new Queue <WorkerResultType>();

            Result = WorkerResultType.None;

            algorithmWorker                 = new ThreadedAlgorithmWorker(Settings.Search_Depth, loggingEnabled);
            algorithmWorker.DoWorkFunc      = algorithmWorker.DoWork_FindPrime;
            algorithmWorker.WorkerComplete += algorithmWorker_WorkerComplete;

            this.RunTime = algorithmWorker.RuntimeTimer;

            primeFindTimer = new Stopwatch();
        }