Reputation: 62
This is my first time with progress bar.I am not able to see the progress indication in my progress bar. I have written the following code.
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Maximum = 1000000;
progressBar1.Value = 0;
progressBar1.Step=10;
Int64 i = 10000000000;
while (i != 1)
{
i = i / 10;
System.Threading.Thread.Sleep(1000);
progressBar1.Increment(10);
}
}
}
}
I dont see any progress shown in my progress bar. Please give me a solution
Upvotes: 2
Views: 586
Reputation: 19151
Your basic use of the progress bar is correct, but there is something weird about some of your other values. In fact, your code will work partly, but the loop will complete before completing the progress bar (my quick calculations indicate that it would take around 28 minutes to complete filling the bar even if your loop continued though! ;) )
In other words, you probably simply did not see the change in the progress bar because it was so small!
A little modification may improve the example a little, and show the progress bar working as intended (and a little quicker than your original code).
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Maximum = 10; // Smaller number of steps needed
progressBar1.Value = 0;
progressBar1.Step = 1;
Int64 i = 10000000000;
while (i != 1) // This will require 10 iterations
{
i = i / 10;
System.Threading.Thread.Sleep(1000);
progressBar1.Increment(1); // one step at a time
}
}
Upvotes: 1
Reputation: 387
Try maximum of 100 ;)
With / 10 you dont make 100000 (1000000 / step 10) runs. you will make 10 ;)
Upvotes: 2