Pergunta

I want to show internet connection speed in a label with the help of timer. I wrote :

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim myNA() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces

    lblConnectStatus.Text = "NET CONNECTION SPEED : " & myNA(0).Speed / 1000000 & " Kbps."
End Sub

This shows 7.2 Kbps. in the label and remains the same all time. Can anyone help..

Foi útil?

Solução

You will have to have something on the internet that you can actually download and use math to determine how long it takes.

There are tones of ways you can do this but the more lower level your function (to get the data) is, the more accurate it will be. IE, if you used something like the Browser control, your result would be low, if even messureable, since you wouldn't know the exact number of bytes you downloaded.

The simplest might be to use something like My.Computer.Network.DownloadFile() (simple, but not the MOST accurate) to download a known large file, like a PDF, and time it using somehting like this:

dim dStart as DateTime = Now
...Download Code
dim ts as TimeSpan = Now.Subtract(dStart)

Then you can take the size of your file, and the time it took to download, to determine the speed.

Outras dicas

Add the following controls:

  • Webbrowser1
  • Button1,text=" Get internet speed"
  • Label1,text="0 Bytes per second"

Paste this code in your program

  Dim t a datetime
 Sub bclk handles button1.click
  Webbrowser1.navigate("stackoverflow.com")
  T= now
 End sub

 Sub wbdoccomplete handles   webbeowser1.documentcomplete
  Dim tspan =now.subtract(t)
  Dim speed as double = (webbrowser1.                        Documenttext.length/tspan.totalseconds)
  Label1.text = speed & " Bytes per second"
End sub
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top