The progress bar is going to 70 just fine. It’s when I go to update it when the loop starts that the bar doesn’t move.
int count = finalFiles.Length; //finalFiles in an array and it varies in size.
int current = 0;
private void uploadWorker_DoWork(object sender, DoWorkEventArgs e)
{
uploadWorker.ReportProgress(20);
DoSomeWork();
uploadWorker.ReportProgress(50);
DoMoreWork();
uploadWorker.ReportProgress(70);
foreach (string file in finalFiles)
{
current++;
doProcess();
uploadWorker.ReportProgress(current / count * 30 + 70);
}
}
Again, the problem is that the progress bar is not updating once it reaches 70. It just doesn’t move. The form does not lock up by the way because I’m using background worker.
Does anyone know why that is?
You have an integer
current, and an integercount. Sincecountis bigger, when you do the division it is always 0 (integer division) untilcurrentreachescurrent. You should either makecountadouble/decimal, or cast one of the two to adouble/decimalbefore doing the division.