I've written a program that uploads a file via FTP to my server. It allows you to select the file you want to upload, type the path to upload it to, then upload it. While it's uploading it uses a loop to keep track of the progress in this format:
bytes uploaded / total bytes
I'm trying to also have it display the percent done (something I thought would be super simple) by having a double called percentDone. Inside the while loop I do this:
percentDone = (int)(totalUploaded / finfo.Length) * 100;
And then the line that prints is:
textbox1.Text = "Uploaded " + totalUploaded + "/" + finfo.Length + " bytes - (" + percentDone + "%)";
Problem is while I'm uploading the percent stays at 0 until the upload is complete, then it jumps to 100%. I've got Application.DoEvents(); inside my while loop, so the textbox text DOES update the uploaded / total part, just not the percent.
Am I doing something wrong? I've tried taking a screenshot of the program while it was uploading and dividing the bytes uploaded by the total bytes, I used these numbers:
657408 / 6598144
Which should give me 0.09963...multiplied by 100 gives me 9.96%. I just want to floor the result, so I'd think that Math.Floor(percentDone) would work. Problem is, like I said, percentDone just stays at 0 for the whole time until the upload is complete.
Please help me out with this, what the heck am I doing wrong?