Answer the question
In order to leave comments, you need to log in
Why is progressBar slow?
The result of exponentiation appears faster than filling the ProgressBar
Code:
private long Pow(long number, int power) {
var result = 1L;
progressBar1.Maximum = power;
if (power == 0)
{
progressBar1.Maximum = 1;
progressBar1.Value = 1;
}
else
{
progressBar1.Value = 0;
while (power > 0)
{
if ((power & 1) == 0)
{
number *= number;
power >>= 1;
progressBar1.Value = progressBar1.Value + power;
}
else
{
result *= number;
--power;
++progressBar1.Value;
}
}
}
return result;
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
label3.Text = Pow((long)numericUpDown1.Value, (int)numericUpDown2.Value).ToString();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
label3.Text = Pow((long)numericUpDown1.Value, (int)numericUpDown2.Value).ToString();
}
}
}
Answer the question
In order to leave comments, you need to log in
Because the ProgressBar component fills smoothly with the OS style. Those. cannot exceed some standard filling rate. Even if you set the value to 0, and then immediately 100, then it will be filled for almost a second. If you want to show the "real" fill rate - draw your own. For example, just place a couple of rectangles on the form. The main one is the frame of the progress bar and the Inner one, which will serve as a fill. Set the size of the inner rectangle based on the percentage of filling of the "progressbar".
And a tip: the progressbar should always have a maximum size of 100 values. 100%. Do not set absolute values for the limit and minimum. Always work with percentages.
Because there is no multithreading. And wrong work with UI. UI is not updated instantly, learn how it works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question