Results 1 to 4 of 4

Thread: [RESOLVED] WebClient.DownloadFileAsync when done?

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] WebClient.DownloadFileAsync when done?

    Ola,

    I'm downloading 5 files async. The downloaded files are replacing important files which are needed to load my app. and the executable itself. The problem is that I don't know when the last file is downloaded.
    vb.net Code:
    1. wclient1.DownloadFileAsync(New Uri(webFolder & fName1), Application.StartupPath & "\" & fName1)
    2. wclient2.DownloadFileAsync(New Uri(webFolder & fName2), Application.StartupPath & "\" & fName2)
    3. wclient3.DownloadFileAsync(New Uri(webFolder & fName3), Application.StartupPath & "\" & fName3)
    4. wclient4.DownloadFileAsync(New Uri(webFolder & fName4), Application.StartupPath & "\" & fName4)
    5. wclient5.DownloadFileAsync(New Uri(webFolder & fName5), Application.StartupPath & "\" & fName5)
    6.  
    7. Private Sub wClient1_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles wclient1.DownloadProgressChanged
    8.     Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
    9.     Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
    10.     Dim percentage As Double = bytesIn / totalBytes * 100
    11. download_progress.Value = Int32.Parse(Math.Truncate(percentage).ToString())
    12.     wclient1.Dispose()
    13. End Sub
    14.  
    15. Private Sub wClient2_.....
    16. '...etc

    What I did was
    vb.net Code:
    1. Private Sub wclient5_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles wclient5.DownloadFileCompleted
    2.     System.Diagnostics.Process.Start(Application.StartupPath & "\my.exe")
    3.     wclient5.Dispose()
    4.     Application.Exit()
    5. End Sub
    ...which is wrong, 'cause I don't know which file is downloaded last.

    Anyone knows how to solve this? Thanks in advance.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2

    Re: WebClient.DownloadFileAsync when done?

    Just keep track via an Integer, adding 1 for each one done. In each completed file routine, just check to see if the Integer is 5 and you know everything is done.

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: WebClient.DownloadFileAsync when done?

    Good one. Let me give it a go and I'll let you know.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: WebClient.DownloadFileAsync when done?

    Works perfect m8. Thanks. Was a pain to solve this issue today and when I figured what I did wrong I couldn't think of something simple.
    Thanks again. +REP

    For the people who want to know how I solved it:

    1) added a label on the form, which counts the "download-done";
    2) added for each webclient I a DownloadFileCompleted;
    3) added in each of the _DownloadFileCompleted the following code: lbl_progress.Text = CStr(CDbl(lbl_progress.Text) + 1)

    And now I can continue
    Last edited by Radjesh Klauke; Nov 3rd, 2011 at 01:22 PM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width