Download individual sequence
Hello!
I'm doing a small download manager, but I was stopped by a little problem xD
So I wanted to add all links to download in a listbox, and download them one at a time not all at once.
This is the code that has the problem NotSupportedException:
Code:
Private Sub down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles down.Click
download = New WebClient
Dim save As String
Dim ab As String
save = urltxt.Text.Split("/"c)(urltxt.Text.Split("/"c).Length - 1)
If urltxt.Text = "http://" Then
MsgBox("Riempi l'url!!", MsgBoxStyle.Critical)
Else
For Each itm As String In ListBox1.Items
download.DownloadFileAsync(New Uri(itm), brwtxt.Text + save)
Next
End If
End Sub
I said that does not support I / O operations simultaneously, but the problem is that I do not want to do any simultaneous action I just want you download the first link when finished proceed to the second, etc.
What's wrong? :sick:
Re: Download individual sequence
That's not how that code will execute, it's going to just spawn a thread for each item and asynchronously download it. You need to handle when the file item finishes, then queue the next one. Right now you are queuing all of them at once.
Re: Download individual sequence
Quote:
Originally Posted by
ForumAccount
That's not how that code will execute, it's going to just spawn a thread for each item and asynchronously download it. You need to handle when the file item finishes, then queue the next one. Right now you are queuing all of them at once.
how should I do? I have to change everything?
1 Attachment(s)
Re: Download individual sequence
I've attached a file called AsyncDownloadManager.vb that can handle this for you. The example code downloads some test/sample files to a directory at C:\test\downloads. The way you would use it is like so:
Code:
Imports System.ComponentModel
Public Class Form1
'//fields
Private WithEvents downloadManager As AsyncDownloadManager
'//event handlers
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Me.downloadManager = New AsyncDownloadManager()
With Me.downloadManager
'//queue an item, the order is the download order
'//pass an uri or an address, and a file name
.Queue("http://wordpress.org/extend/plugins/about/readme.txt", _
"C:\test\downloads\readme.txt")
.Queue("http://www.catea.gatech.edu/grade/fs/10_CSS.pdf", _
"C:\test\downloads\10_CSS.pdf")
.Queue("http://www.textfiles.com/hacking/homebank.txt", _
"C:\test\downloads\homebank.txt")
.Queue("http://illiad.evms.edu/sample.pdf", _
"C:\test\downloads\sample.pdf")
'//start async download
.BeginDownload()
End With
End Sub
Private Sub DownloadCompleted(ByVal sender As Object, _
ByVal e As AsyncCompletedEventArgs) _
Handles downloadManager.DownloadCompleted
'//all files are done, clean up
Me.downloadManager.Dispose()
Me.downloadManager = Nothing
End Sub
End Class
This would be the extent of use. Everything else will be handled for you.
Re: Download individual sequence