Esempio n. 1
0
    public void DoProgress(int index = -1, string operation = null)
    {
        bool process = true;
        bool refresh = false;

        if (UseQuanta)
        {
            CurrentQuanta++;
            if (CurrentQuanta >= QuantaLevel)
            {
                CurrentQuanta = 0;
            }
            else
            {
                process = false;
            }
        }
        if (!operation.IsNullOrEmpty())
        {
            LabelOperation.Text = operation;
            refresh             = true;
        }
        if (process)
        {
            if (index == -1)
            {
                ProgressBar.PerformStep();
            }
            else
            {
                ProgressBar.Value = index;
            }
            if (LabelCount.Visible)
            {
                LabelCount.Text = $"{ProgressBar.Value}/{ProgressBar.Maximum}";
            }
            refresh = true;
            BringToFront();
        }
        if (refresh)
        {
            Refresh();
        }
        if (Progressing is not null)
        {
            SystemManager.TryCatchManage(() => Progressing.Invoke());
        }
        if (ActionCancel.Visible)
        {
            Application.DoEvents();
        }
    }
Esempio n. 2
0
        public List <int> GetAllPrimesBelowNumber(int pNumber)
        {
            if (pNumber < 1)
            {
                throw new ArgumentOutOfRangeException();
            }
            Initializing?.Invoke(this, new EventArgs());
            List <int> allPrimes = new List <int>();

            for (int current = 1; current < pNumber; current++)
            {
                bool isPrime = IsPrimeNumber(current);
                if (isPrime)
                {
                    Thread.Sleep(10);
                    allPrimes.Add(current);
                    Progressing?.Invoke(this, new ProgressingEventArgs(pNumber, current));
                }
            }
            Completed?.Invoke(this, new PrimeCompletedEventArgs(pNumber, allPrimes, new TimeSpan(0)));
            return(allPrimes);
        }