determining transfer rate
-
hey guys, im writing a custom auto updater, its pretty much done, and i would like to incorporate a file transfer rate (Downloading at 288 KB/s) for when the updates are being downloaded. ive searched google, searched here, couldnt come up with a valid tutorial. im using webclient.downloadfileasync() to get the actual file, any help would be appreciated.
-
hey guys, im writing a custom auto updater, its pretty much done, and i would like to incorporate a file transfer rate (Downloading at 288 KB/s) for when the updates are being downloaded. ive searched google, searched here, couldnt come up with a valid tutorial. im using webclient.downloadfileasync() to get the actual file, any help would be appreciated.
If you are looking for average transfer rate and/or time remaining, it is fairly simple. Transfer Rate = amount downloaded / seconds elapased. Remaining Time = Total Size - Amount Downloaded / Transfer Rate. If you are using FTP as your mechanism... Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 2048; int readCount; byte[] buffer = new byte[bufferSize]; int readCount = ftpStream.Read(buffer, 0, bufferSize); //download as long as the download is not cancelled. while (readCount > 0 && _continueUpdating) { //For calculationg speed and other good stuff. _bytesReceived += readCount; outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); } Good luck, I hope this helps!