Finding Download Speed using DownloadFileAsync

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?=

    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
  • Peter Duniho

    #2
    Re: Finding Download Speed using DownloadFileAsy nc

    On Thu, 17 Jul 2008 08:51:02 -0700, greatbarrier86
    <greatbarrier86 @discussions.mi crosoft.comwrot e:
    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.Downl oadFileAsync(), 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

    Comment

    • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

      #3
      RE: Finding Download Speed using DownloadFileAsy nc

      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 DownloadProgres sChanged event.
      3) When the event is fired, the DownloadProgres sChangedEventAr gs 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 DownloadProgres sChangedEventAr gs also has the TotalBytesToRec eive
      property which you can use along with the speed to work out the time
      remaining.

      Hope this helps

      --
      Ciaran O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }



      "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

      Comment

      Working...