c# - What is wrong when trying to find how much bytes sent(uploaded) so far? -
i have event i'm doing progress report backgroundworker1 progresschanged event:
mbsent = ((double)obj.bytessent) / (1 << 20); stringprogressreport[2] = mbsent.tostring(); backgroundworker1.reportprogress(0, 2);
mbsent global double var. , stringprogressreport string array var. have var type long called totalbytes file i'm uploading size. i'm not using var here maybe should.
then in backgroundworker progresschanged event did:
label5.text = stringprogressreport[2];
the problem in label5 see counting int numbers 1,2,3,4,5...when it's getting 25 in end see number 25 become 25.34543356767 , totalbytes size else @ it's 26.7898 or something.
something wrong this: mbsent = ((double)obj.bytessent) / (1 << 20); maybe need sue here somehow totalbytes(the file total size) ?
this how i'm calculating totalbytes:
long totalbytes = 0; private void button3_click(object sender, eventargs e) { openfiledialog openfiledialog1 = new openfiledialog(); openfiledialog1.initialdirectory = "c:\\"; openfiledialog1.filter = "mp4 files (*.mp4)|*.mp4|all files (*.*)|*.*"; if (openfiledialog1.showdialog() == dialogresult.ok) { filenametoupload = openfiledialog1.filename; filename = openfiledialog1.filename; using (filestream filestream = file.openread(filename)) { totalbytes = filestream.length; } } }
there's nothing wrong calculation. if don't want see decimals in output either don't convert mbsent
double or use format string in tostring()
call.
either:
mbsent = obj.bytessent / (1 << 20);
or:
stringprogressreport[2] = mbsent.tostring("d");
and when totalbytes
26,789,800, mbsent 25.45874420 correct. 20,789,800 / 1,048,576 = 25.45874420.
Comments
Post a Comment