Multiple Inet's

Motortracker
01-05-2008, 10:29 PM
ok i am trying to download multiple files at a time using Inet.

so on form2 i am using inet1. the file starts downloading just fine. then i changed inet1 to inet2 on form3. thinking that would let me download 2 files using 2 different inets. but as soon as inet2 starts downloading it stops inet1 from downloading.

Form1

Private Sub Command1_Click()

Do until i = 2
If Form2.Visible = False Then
Url = "www.someurl.com/test.txt
Filename = test.txt
Form2.Show

Else
Url = "www.someurl.com/test2.txt
Filename = test2.txt
Form3.Show
Loop
End If

End Sub


Form2


Private Sub Form_Load()
Sec = 1
SaveLocation = "C:\" & FileName
Download
End Sub

Private Sub Download()
Timer1.Enabled = True
Command1.Enabled = False
'start download
Inet1.Execute Trim$(Url), "GET"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim Buffer() As Byte 'buffer for receiving data from inet control.
On Error Resume Next
Select Case State
Case icResponseCompleted
Open SaveLocation For Binary As #1 'open output file
Do
DoEvents
Buffer = Inet1.GetChunk(512, icByteArray) 'get the data chunk
If UBound(Buffer) = -1 Then Exit Do 'no more data
Put #1, , Buffer 'write data to file
ProgressBar1.Value = Seek(1) - 1 'ammount of data downloaded
' Label1.Caption = "Downloaded " & ProgressBar1.Value \ 1024 & " kb, " & _
' FormatPercent(ProgressBar1.Value / ProgressBar1.Max)
Loop
Close
Picture = LoadPicture(SaveLocation) 'display the downloaded image
Case icResponseReceived
If LenB(Inet1.GetHeader("Content-Length")) > 0 Then
ProgressBar1.Max = CLng(Inet1.GetHeader("Content-Length")) 'total size
End If
End Select
End Sub


Form3


Private Sub Form_Load()
Sec = 1
SaveLocation = "C:\" & FileName
Download
End Sub

Private Sub Download()
Timer1.Enabled = True
Command1.Enabled = False
'start download
Inet2.Execute Trim$(Url), "GET"
End Sub

Private Sub Inet2_StateChanged(ByVal State As Integer)
Dim Buffer() As Byte 'buffer for receiving data from inet control.
On Error Resume Next
Select Case State
Case icResponseCompleted
Open SaveLocation For Binary As #1 'open output file
Do
DoEvents
Buffer = Inet2.GetChunk(512, icByteArray) 'get the data chunk
If UBound(Buffer) = -1 Then Exit Do 'no more data
Put #1, , Buffer 'write data to file
ProgressBar1.Value = Seek(1) - 1 'ammount of data downloaded
' Label1.Caption = "Downloaded " & ProgressBar1.Value \ 1024 & " kb, " & _
' FormatPercent(ProgressBar1.Value / ProgressBar1.Max)
Loop
Close
Picture = LoadPicture(SaveLocation) 'display the downloaded image
Case icResponseReceived
If LenB(Inet2.GetHeader("Content-Length")) > 0 Then
ProgressBar1.Max = CLng(Inet2.GetHeader("Content-Length")) 'total size
End If
End Select
End Sub

Motortracker
01-05-2008, 10:43 PM
I know i can do this if i make the Inet Into Seperate exe's but i would like to keep it all in one exe. because if i open multiple versions of the exe i can download mulitple files i just have to have 2 exe's open. Any Idea's?

Motortracker
01-05-2008, 11:35 PM
Here is what it looks like.

now after form3 and starts downloading the next file the Time Elapsed still keeps going up on form2 so i know my timers and everything are still working it is like it just cancels the Inet1 from form2 completely.

dilettante
01-06-2008, 08:20 AM
There may be parts of this control that limit it to one activity on a given process/thread. I know that since it uses the WinInet API internally it is limited to a few (2? 3?) simultaneous operations, because WinInet is using the guts of IE (or is part of said entrails), and IE was changed early on to limit the number of parallel active transfers because it was overloading web servers.

The XMLHTTPRequest object has the same throttle in place because it works the same way as Inet in this regard.

The "fix" for this is to use either the ServerXMLHTTPRequest object (NT 4.0 or later, requires MSXML 3.0 or later) or the WinHTTP object (XP or later) which do not go through IE components.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum