Progress Bar macht nix

  • VB.NET

Es gibt 18 Antworten in diesem Thema. Der letzte Beitrag () ist von Fabian0608.

    Progress Bar macht nix

    Guten tag und zwar macht meine Progress bar nix
    Folgender Code:

    VB.NET-Quellcode

    1. Private Sub FTPClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles FTPClient.DownloadProgressChanged
    2. Me.ProgressBar1.Value = e.ProgressPercentage
    3. End Sub
    4. End Class


    und Einmal hier DIe downloads:

    VB.NET-Quellcode

    1. FTPClient.DownloadFile(New Uri(""), "C:/Arma 3 Mods/.rar")
    2. FTPClient.DownloadFile(New Uri(""), "C:/Arma 3 Mods/.rar")
    3. FTPClient.DownloadFile(New Uri(""), "C:/Arma 3 Mods/.rar")
    4. FTPClient.DownloadFile(New Uri(""), "C:/Arma 3 Mods/.rar")
    5. FTPClient.DownloadFile(New Uri(""), "C:/Arma 3 Mods/.rar")


    Die haben kein Download Link weil ich erst die Progress Bar hin bekommen will
    ich weiss nicht aber liegt das daran das ich

    VB.NET-Quellcode

    1. DownloadFile
    statt

    VB.NET-Quellcode

    1. DownloadDataAsync
    benutze ?

    Hoffe mir kann Jemand helfen

    VB.NET-Quellcode

    1. ' WebClient instanzieren
    2. Using ftpClient As New WebClient()
    3. ftpClient.DownloadFileCompleted += New AsyncCompletedEventHandler(DownloadCompleted) 'Das müsstest du selbst nocheinmal verbessern, dürfte so nicht passen
    4. ftpClient.DownloadProgressChanged += New DownloadProgressChangedEventHandler(ProgressChanged) 'Das müsstest du selbst nocheinmal verbessern, dürfte so nicht passen
    5. ftpClient.DownloadFileAsync(New Uri(""), "C:/Arma 3 Mods/.rar")
    6. End Using
    7. ' WebClient -Events
    8. Private Sub ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
    9. progressBar1.value = e.ProgressPercentage
    10. End Sub
    11. Private Sub DownloadCompleted(sender As Object, e As AsyncCompletedEventArgs)
    12. End Sub

    Fabian0608 schrieb:

    da ich dann keine Mehrere Downloads machen kann
    Gugst Du hier.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    RodFromGermany schrieb:

    Gugst Du hier.


    Auch das kenn ich und verstehe ich nicht so richtig xD

    hab aber auch noch was anderes gefunden:

    VB.NET-Quellcode

    1. Try
    2. Dim Counter As Int16 = 0
    3. Do Until Counter = 2 ' Files die gesaugt werden sollen
    4. Dim FTPClient As New System.Net.WebClient 'Erzeugt immer einen neuen WebClient
    5. AddHandler FTPClient.DownloadFileCompleted, AddressOf FTPClient_DownloadFileCompleted
    6. Counter = Counter + 1
    7. Dim source As Uri
    8. Dim target As String
    9. source = New Uri("ftp://Server" & Counter & ".rar")
    10. target = "C:/Arma 3 Mods" & Counter & "ACE.rar"
    11. FTPClient.DownloadFileAsync(source, target)
    12. Loop
    13. Catch ex As Exception
    14. MsgBox(ex.Message)
    15. End Try


    ich geb dort zwar dann die URL ein jedoch passiert nix also es wird nix Runtergeladen
    und der hier wird auch aufgerufen

    VB.NET-Quellcode

    1. Private Sub FTPClient_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles FTPClient.DownloadFileCompleted
    2. Beep()
    3. 'MsgBox("Download Fertig", MsgBoxStyle.Information, "Erlogreich")
    4. End Sub


    aber der:

    VB.NET-Quellcode

    1. Private Sub FTPClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles FTPClient.DownloadProgressChanged
    2. Beep()
    3. Me.ProgressBar1.Value = e.ProgressPercentage
    4. End Sub

    Trozdem nicht

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Fabian0608“ ()

    Du hast den Event auch nicht aboniert.

    VB.NET-Quellcode

    1. AddHandler FTPClient.DownloadProgressChanged, AddressOf FTPClient_DownloadProgressChanged


    *Edit*
    Aber das Snippet ist nicht gerade schön. Hier wird ja für jeden Download ein neuer WebClient instanziert ohne den die lezte Instanz davon wieder zu zerstören (Dispose aufrufen)

    VB.NET-Quellcode

    1. AddHandler FTPClient.DownloadProgressChanged, AddressOf FTPClient_DownloadProgressChanged



    Hier wäre mal mein komplett -Vorschlag, getestet und Funktioniert.
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class Form1
    2. ' Dictionary beinhaltet alle DownloadLinks
    3. Private dicDownloadList As Dictionary(Of Uri, String)
    4. ' Verzeichniss in dem die Mods gespeichert werden sollen
    5. Private diModDirectory As System.IO.DirectoryInfo
    6. ' WebClient für die Downloads deklarieren
    7. Private ftpClient As System.Net.WebClient
    8. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    9. ' Downloadliste befüllen
    10. dicDownloadList = New Dictionary(Of Uri, String)()
    11. dicDownloadList.Add(New Uri("http://127.0.0.1/downloads/downloads.rar"), "Mod_xxx_1.rar")
    12. dicDownloadList.Add(New Uri("http://127.0.0.1downloads/downlaods_1.rar"), "Mod_xxx_2.rar")
    13. ' Verzeichniss für die Mods festlegen
    14. diModDirectory = New System.IO.DirectoryInfo("C:/Arma 3 Mods/")
    15. If Not diModDirectory.Exists Then
    16. diModDirectory.Create()
    17. End If
    18. ' Jedes Element in unserer DownloadListe durchlaufen und herunterladen
    19. For Each download As KeyValuePair(Of Uri, String) In dicDownloadList
    20. Using ftpClient As New System.Net.WebClient()
    21. AddHandler ftpClient.DownloadFileCompleted, AddressOf FTPClient_DownloadFileCompleted
    22. AddHandler ftpClient.DownloadProgressChanged, AddressOf ftpClient_DownloadProgressChanged
    23. ftpClient.DownloadFileAsync(download.Key, System.IO.Path.Combine(diModDirectory.FullName, download.Value))
    24. End Using
    25. Next
    26. End Sub
    27. Private Sub ftpClient_DownloadProgressChanged(sender As Object, e As System.Net.DownloadProgressChangedEventArgs)
    28. Me.ProgressBar1.Value = e.ProgressPercentage
    29. End Sub
    30. Private Sub FTPClient_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
    31. Beep()
    32. 'MsgBox("Download Fertig", MsgBoxStyle.Information, "Erlogreich")
    33. End Sub
    34. End Class

    Allerdings werden sich hier die Fortschritte der verschiedenen Downloads in die Quere kommen.

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Fakiz“ ()

    VB.NET-Quellcode

    1. Public Class Form1
    2. ' Dictionary beinhaltet alle DownloadLinks
    3. Private dicDownloadList As Dictionary(Of Uri, String)
    4. ' Verzeichniss in dem die Mods gespeichert werden sollen
    5. Private diModDirectory As System.IO.DirectoryInfo
    6. ' WebClient für die Downloads deklarieren
    7. Private ftpClient As System.Net.WebClient

    Das ist klar das kommt oben unter Public Class

    und das kann ich rein theroretisch unterm Download Button legen oder ?

    VB.NET-Quellcode

    1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2. ' Downloadliste befüllen
    3. dicDownloadList = New Dictionary(Of Uri, String)()
    4. dicDownloadList.Add(New Uri("http://127.0.0.1/downloads/downloads.rar"), "Mod_xxx_1.rar")
    5. dicDownloadList.Add(New Uri("http://127.0.0.1downloads/downlaods_1.rar"), "Mod_xxx_2.rar")
    6. ' Verzeichniss für die Mods festlegen
    7. diModDirectory = New System.IO.DirectoryInfo("C:/Arma 3 Mods/")
    8. If Not diModDirectory.Exists Then
    9. diModDirectory.Create()
    10. End If
    11. ' Jedes Element in unserer DownloadListe durchlaufen und herunterladen
    12. For Each download As KeyValuePair(Of Uri, String) In dicDownloadList
    13. Using ftpClient As New System.Net.WebClient()
    14. AddHandler ftpClient.DownloadFileCompleted, AddressOf FTPClient_DownloadFileCompleted
    15. AddHandler ftpClient.DownloadProgressChanged, AddressOf ftpClient_DownloadProgressChanged
    16. ftpClient.DownloadFileAsync(download.Key, System.IO.Path.Combine(diModDirectory.FullName, download.Value))
    17. End Using
    18. Next
    19. End Sub

    und das ist auch klar

    VB.NET-Quellcode

    1. Private Sub ftpClient_DownloadProgressChanged(sender As Object, e As System.Net.DownloadProgressChangedEventArgs)
    2. Me.ProgressBar1.Value = e.ProgressPercentage
    3. End Sub
    4. Private Sub FTPClient_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
    5. Beep()
    6. 'MsgBox("Download Fertig", MsgBoxStyle.Information, "Erlogreich")
    7. End Sub
    8. End Class

    Allerdings werden sich hier die Fortschritte der verschiedenen Downloads in die Quere kommen.

    hauptsache zeigt an das der Download Auch fertig ist

    Habs jetz so gemacht wie ichs geschrieben hab es wird auch gedownloadet aber dennoch passiert nix
    ausserdem kommt die Message das der download Komplett ist direkt am anfang

    /edit ok er downloaded es doch nicht die datei erscheint zwar aber sie ist leer bzw beschädigt
    Vielleicht liegts daran das der sich erst auf den FTP einloggen muss

    VB.NET-Quellcode

    1. ftpClient.Credentials = New NetworkCredential("Username", "Passwort")


    habs auch als erstes hingeschriebenwenn auf den Button Geklickt wird

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Fabian0608“ ()