471,354 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Finding Download Speed using DownloadFileAsync

Hi,

I know there isn't a specific event property for the download speed, but can
anyone tell me how to find it? I'm not sure how to write the code.

Thanks,
Jason
Jul 17 '08 #1
2 5656
On Thu, 17 Jul 2008 08:51:02 -0700, greatbarrier86
<gr************@discussions.microsoft.comwrote:
I know there isn't a specific event property for the download speed, but
can
anyone tell me how to find it? I'm not sure how to write the code.
Using WebClient.DownloadFileAsync(), I don't think there's a good way to
do it. AFAIK, the WebClient class doesn't expose the information, nor
does it expose enough information for you to calculate it.

If you do the download yourself with an i/o class like NetworkStream, you
can explicitly read the data is small chunks (e.g. 8K at a time) and then
periodically calculate the download speed yourself (data read divided by
time is speed).

Pete
Jul 17 '08 #2
Before calling the function you need to do two things:
1) Either the record the time or create and start a Stopwatch in a class
level variable (function level is you use an anonymous function for part 2)
2) Add an event handler to the DownloadProgressChanged event.
3) When the event is fired, the DownloadProgressChangedEventArgs has
BytesReceived property, you can then see either
a) how much has been downloaded and the elasped time since the last time the
event was fired for a current rate, or how much since the start of downlaod
to get an average rate for the file (less helpful to a watching user of
course).

The DownloadProgressChangedEventArgs also has the TotalBytesToReceive
property which you can use along with the speed to work out the time
remaining.

Hope this helps

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"greatbarrier86" wrote:
Hi,

I know there isn't a specific event property for the download speed, but can
anyone tell me how to find it? I'm not sure how to write the code.

Thanks,
Jason
Jul 18 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matthew Sims | last post: by
4 posts views Thread by D. Alvarado | last post: by
5 posts views Thread by gjzusenet | last post: by
6 posts views Thread by Giovanni | last post: by
1 post views Thread by bigpoppa | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.