I assume you want kb / sec. This is determined by taking kbreceived and dividing it by current seconds minus the initial seconds. I'm not sure how to make a DateTime for this in C #, but in VC ++ it will be like this:
COleDateTimeSpan dlElapsed = COleDateTime::GetCurrentTime() - dlStart; secs = dlElapsed.GetTotalSeconds();
Then you split:
double kbsec = kbreceived / secs;
To get kbreceived , you need to take currentBytes to read, add bytes already read, and 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 specific implementation functions, the basic concept is the same regardless of language.
user195488
source share