Clocking transfer rate in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • None

    Clocking transfer rate in c#

    I'm using the HttpWebRequest/Response methods and I'm trying to figure
    out how to calculate the effective transfer rare the file is being
    received at (like you see in IE when you download something). I have
    already learned how to do a "progress bar" type solution, which lets
    me calculate percentages. This is different however, because rate
    implies time.

    I've tried making a timer that goes off once a second and then
    applying (bytes downloded now - bytes downloaded last interval), I get
    inaccurate speed (584 KB/s when it's more like 230 KB/s)

    then I tried recording the ticks between 2 successive read calls in a
    loop, dividing that by the number of ticks in a second, getting the
    inverse of that and multiplying by 4 (bc my buffer is 4k). Still no
    good

    If anyone has any solutions I'd love to hear them. Thanks.
  • Alex Egg

    #2
    RE: Clocking transfer rate in c#

    I did something like this... It seems accurate

    //SPEED STUF
    counter++
    int speed=lsize/counter
    guid.labelSpeed .Text=speed.ToS tring()+" Kb/s"

    this code is in my Timer1_Tick method, it is called every second. counter is type int and every second it is divided into the size of the file being downloaded to my hard drive. So if lsize = 126KB and counter =9; my download speed would be 14Kb/s (126/9=14). At least I think this is how it worked... I havent looked at this code in a longggg time

    It sounds good to me. I just take the size of how much of the file has been placed on my drive, then divide the size by the amount of time it took to get that much. Yeah. this should work fine.

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Clocking transfer rate in c#

      None <maniac4cs@hotm ail.com> wrote:[color=blue]
      > I'm using the HttpWebRequest/Response methods and I'm trying to figure
      > out how to calculate the effective transfer rare the file is being
      > received at (like you see in IE when you download something). I have
      > already learned how to do a "progress bar" type solution, which lets
      > me calculate percentages. This is different however, because rate
      > implies time.
      >
      > I've tried making a timer that goes off once a second and then
      > applying (bytes downloded now - bytes downloaded last interval), I get
      > inaccurate speed (584 KB/s when it's more like 230 KB/s)
      >
      > then I tried recording the ticks between 2 successive read calls in a
      > loop, dividing that by the number of ticks in a second, getting the
      > inverse of that and multiplying by 4 (bc my buffer is 4k). Still no
      > good[/color]

      Don't multiply by the buffer size - multiply by how many bytes you
      actually received, which may not be the same as the buffer size.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...