Salve, vorrei visualizzare in una label la velocità di download espressa in kb, io per scaricare un file uso questo codice:
codice:Public WithEvents TCP As New System.Net.WebClientcodice:Public Mem1 As String, Mem2 As StringCome posso risolvere il problema?codice:Private Sub PrgChngd(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles TCP.DownloadProgressChanged ProgressBar1.Value = e.ProgressPercentage If e.TotalBytesToReceive > 1073741824 Then Mem1 = Math.Round((((e.TotalBytesToReceive / 1024) / 1024) / 1024), 2) & " GB" Else Mem1 = Math.Round((((e.TotalBytesToReceive / 1024) / 1024)), 2) & " MB" End If Label3.Text = Mem1 If e.BytesReceived > 1073741824 Then Mem2 = Math.Round((((e.BytesReceived / 1024) / 1024) / 1024), 2) & " GB" Else Mem2 = Math.Round((((e.BytesReceived / 1024) / 1024)), 2) & " MB" End If Label4.Text = Mem2 Label5.Text = e.ProgressPercentage & "%" End Sub Private Sub PrgComplete(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles TCP.DownloadFileCompleted If e.Cancelled = True Then MessageBox.Show("Errore! Il download non è stato completato!", "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error) Else MessageBox.Show("Il Download è stato completato con successo!", "Download Completo", MessageBoxButtons.OK, MessageBoxIcon.Information) End If Button1.Text = "Scarica" End Sub Public Sub Download() If Button1.Text = "Scarica" Then On Error GoTo Err SaveFileDialog1.FileName = Listview1.SelectedItems(0).SubItems(1).Text & ".mp4" DialogResult = SaveFileDialog1.ShowDialog() If DialogResult = Windows.Forms.DialogResult.OK Then TCP.DownloadFileAsync(New Uri(ListView2.SelectedItems(0).SubItems(1).Text), SaveFileDialog1.FileName) Button1.Text = "Ferma" End If Else TCP.CancelAsync() Button1.Text = "Scarica" Label3.Text = "" Label4.Text = "" Label5.Text = "" ProgressBar1.Value = 0 End If Exit Sub Err: MessageBox.Show("Errore! " & ErrorToString(), "Errore!", MessageBoxButtons.OK, MessageBoxIcon.Error) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Download() End Sub
Grazie in anticipo

Rispondi quotando