I'm guessing you want kb/sec. That is determined by taking kbreceived
and dividing it by the current seconds minus the starting seconds. I'm not sure how to do the DateTime for this in C#, but in VC++ it would be like so:
COleDateTimeSpan dlElapsed = COleDateTime::GetCurrentTime()
- dlStart;
secs = dlElapsed.GetTotalSeconds();
You then divide:
double kbsec = kbreceived / secs;
To get kbreceived
, you need to take the currentBytes
read, add in bytes already read, then divide by 1024.
So,
// chunk size 512.. could be higher up to you
while (int bytesread = file->Read(charBuf, 512))
{
currentbytes = currentbytes + bytesread;
// Set progress position by setting pos to currentbytes
}
int percent = currentbytes * 100 / x ( our file size integer
from above);
int kbreceived = currentbytes / 1024;
Minus some implementation specific functions, the basic concept is the same regardless of language.