gerz0ckerz
Goto Top

Wie berechene ich die Download Geschwindigkeit?

Ich möchte die Geschwindigkeit eines Downloads berechnen der per Webclient.Downloadfileasync gestartet wird in KB/S und MB/S berechnen, wie stelle ich das an?

Content-ID: 310625

Url: https://administrator.de/contentid/310625

Ausgedruckt am: 22.11.2024 um 16:11 Uhr

129813
Lösung 129813 23.07.2016 aktualisiert um 10:32:50 Uhr
Goto Top
speed = data / interval

Did you miss the first math lessons in school face-smile?

VB.Net example Form
Imports System.Net

Public Class Form1
    WithEvents client As WebClient
    Dim currentBytes As Long = 0
    Dim lastBytes As Long = 0
    WithEvents tm As Timer

    Private Sub btnDownload_Click(sender As Object, e As EventArgs) Handles btnDownload.Click
        client = New WebClient
        tm = New Timer()
        With tm
            .Interval = 500
            .Start()
        End With
        client.DownloadFileAsync(New Uri("http://domain/download.iso"), Environ("Temp") & "\test.iso")  
    End Sub

    Private Sub client_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles client.DownloadProgressChanged
        pBar.Value = e.ProgressPercentage
        currentBytes = e.BytesReceived
    End Sub

    Private Sub btnStopDownload_Click(sender As Object, e As EventArgs) Handles btnStopDownload.Click
        client.CancelAsync()
        tm.Stop()
    End Sub

    Private Sub tm_Tick(sender As Object, e As EventArgs) Handles tm.Tick
        Dim speed As String
        Dim lngDataPerInterval As Long = currentBytes - lastBytes
        If lngDataPerInterval < (1024 * 1024) Then
            speed = Math.Round((lngDataPerInterval / 1024) / (tm.Interval / 1000), 0) & " KB/s"  
        Else
            speed = Math.Round((lngDataPerInterval / (1024 * 1024)) / (tm.Interval / 1000), 2) & " MB/s"  
        End If
        lblStatus.Text = speed
        lastBytes = currentBytes
    End Sub
End Class
Regards
aqui
aqui 23.07.2016 um 10:32:30 Uhr
Goto Top
Did you miss the first math lessons in school
Indeed ! Missed completely what we call in the German Grundschule "das kleine Einmaleins" !
129813
129813 23.07.2016 aktualisiert um 10:38:46 Uhr
Goto Top
Zitat von @aqui:
Did you miss the first math lessons in school
Indeed ! Missed completely what we call in the German Grundschule "das kleine Einmaleins" !
I suppose, teached by Super Mario face-big-smile
aqui
aqui 23.07.2016 aktualisiert um 16:17:31 Uhr
Goto Top
two fours love each other and get a baby 4....GREAT !!! face-big-smile

On top a stupid doublepost:
Webclient Download Größe in KB, MB etc. umrechnen