VB.NET DownloadProgressChanged Event

ghostadmin

Grand Admiral Special
Mitglied seit
11.11.2001
Beiträge
25.179
Renomée
184
Standort
Dahoam Studios
Bei folgendem Code habe ich das Problem das das File zwar heruntergeladen wird aber die Progressbar erst am Ende auf 100 springt und die Größe in der Statusbar angezeigt wird (xx von xx bytes). Während dem Download ändert sich nichts.

Code:
Option Strict Off
Option Explicit On
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Net
Imports System.ComponentModel

Public Class Dialog3
    Dim myClient As New Net.WebClient

    Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
        ProgressBar1.Value = e.ProgressPercentage
        StatusBar1.Panels(1).Text = e.BytesReceived.ToString("0,0") & " from " & e.TotalBytesToReceive.ToString("0,0")
    End Sub

    Private Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        ProgressBar1.Value = 0
        If e.Cancelled Then
            MessageBox.Show("Download was interrupted", "Download", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Else
            MessageBox.Show("Download was successfull", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    'Download file from web. 	
    Private Sub cmddownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddownload.Click
        AddHandler myClient.DownloadFileCompleted, AddressOf Me.DownloadFileCompleted
        AddHandler myClient.DownloadProgressChanged, AddressOf Me.DownloadProgressChanged
        StatusBar1.Panels(0).Text = "Download"
        Dim DR As DialogResult = FolderBrowserDialog1.ShowDialog
        If DR = Windows.Forms.DialogResult.OK Then
            myClient.DownloadFileAsync(New Uri(Web_Update.Downuri), _
            FolderBrowserDialog1.SelectedPath.ToString & _
            "\file.msi")
        End If
        'Me.Close()
        'Application.Exit()
    End Sub

 


End Class
 
Zurück
Oben Unten