5 Replies - 360 Views - Last Post: 23 April 2012 - 09:43 AM Rate Topic: -----

#1 xxxartistxxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

VB.NET Download Files One by One

Posted 23 April 2012 - 04:04 AM

Hello Everyone,
I have a problem with my file download function.
This's my function
Private Function download_files(ByVal _URL As System.Uri, ByVal _SaveAs As String)
        If InternetConnection() = True Then
            Dim _WebClient As New System.Net.WebClient()
            Try
                AddHandler _WebClient.DownloadProgressChanged, AddressOf _DownloadProgressChanged
                lblStatus.Text = "Downloading File :" & _SaveAs
                _WebClient.DownloadFileAsync(_URL, _SaveAs)
                Return True
            Catch ex As Exception
                _WebClient = Nothing
                Return False
                lblStatus.Text = "Güncelleme Sunucusuna Bağlantı Başarısız Oldu."
            End Try
        Else
            lblStatus.Text = "Güncelleme Sunucusuna Bağlantı Başarısız Oldu."
        End If
    End Function

And this's my download loop
    Private Sub download()
        Dim x As Integer
        For x = 0 To lstUrlsToDownload.Items.Count - 1
            download_files(New Uri(lstUrlsToDownload.Items.Item(x).ToString), "c:\" & lstFilesToDownload.Items.Item(x).ToString)
        Next
    End Sub

In lstUrlsToDownload i have url's for example
http://www.sth.com/sth.txt
http://www.abc.com/abc.txt
In lstFilesToDownload i have file names in the same order as urls for example
sth.txt
abc.txt
My problem is with my loop all files downloading at the same time but i want to download them one by one one will finish and other will start and goes like that how can i do that thanks so much good forums to everyone :balloon:

Is This A Good Question/Topic? 0
  • +

Replies To: VB.NET Download Files One by One

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 6436
  • View blog
  • Posts: 23,428
  • Joined: 12-June 08

Re: VB.NET Download Files One by One

Posted 23 April 2012 - 07:16 AM

You need to stop and think about what you are doing. You are spinning up new objects and what not in a for loop with no feedback that it's done... perhaps make your 'download' function return a boolean if it is done or not.. and the for loop condition only cycling wait for it to return true or false..
Was This Post Helpful? 0
  • +
  • -

#3 xxxartistxxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: VB.NET Download Files One by One

Posted 23 April 2012 - 07:21 AM

View Postmodi123_1, on 23 April 2012 - 07:16 AM, said:

You need to stop and think about what you are doing. You are spinning up new objects and what not in a for loop with no feedback that it's done... perhaps make your 'download' function return a boolean if it is done or not.. and the for loop condition only cycling wait for it to return true or false..

Thanks i'll try it
Was This Post Helpful? 0
  • +
  • -

#4 xxxartistxxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: VB.NET Download Files One by One

Posted 23 April 2012 - 07:53 AM

I tried but i can't do it:( could you give me some tricks
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 6436
  • View blog
  • Posts: 23,428
  • Joined: 12-June 08

Re: VB.NET Download Files One by One

Posted 23 April 2012 - 08:54 AM

I have no idea what you tried.. how about you show me..
Was This Post Helpful? 0
  • +
  • -

#6 xxxartistxxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-April 12

Re: VB.NET Download Files One by One

Posted 23 April 2012 - 09:43 AM

View Postmodi123_1, on 23 April 2012 - 08:54 AM, said:

I have no idea what you tried.. how about you show me..

I will try something and write result ASAP Thanks.
[/code]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1