472,371 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Launching and controlling multiple simultaneous threads with vb.net

I have a situation where I need to download multiple files in a vb.net
application.

To speed up the process, I am trying to download multiple files at one
time looping through each of the files and launching them in their own
thread (code below). The problem is that when there are hundreds of
files to download, it launches them all at the same time and half
don't get downloaded. Any idea how I could control it to launch say 4
at a time, so that when one finished another would launch until the
batch is complete? Was thinking message queues but am not sure if this
is the right path to take.

Any help is appreciated
Dim count As Integer
'loop through each file
For count = CType(txturlcountbegin.Text, Integer) To
CType(txturlcountend.Text, Integer)
' create new download object
Dim c As Common = New Common
' Hoook up the on download complete event
AddHandler c.FileDownloaded, AddressOf filesaved
'Set the file download properties
c.fn = txtFileName.Text
c.sp = txtSavePath.Text
c.wc = txtWildCard.Text
c.tb = txtBegin.Text
c.te = txtEnd.Text
c.url = Regex.Replace(txtURL.Text, txtURLWILDCARD.Text,
count.ToString)
c.batchnum = count
'launch a new thread to download the files
Dim t As New Thread(New ThreadStart(AddressOf c.getFiles))
t.Start()
Next
Nov 21 '05 #1
1 3344
Hi Ryan

Your problem is that are creating a new thread insisde
the for cylcle. I would use it to store your common
objects inside a arraylist.

Create a class with a thread counter set to zero by
default.

create a while cycle with a boolean variable.
Inside the cycle always retreive the 1st element of
arraylist and if thread counter < 5 create a new thread
with Common object and increase the counter inside your
GetFiles and remove the item from the arraylist.

Once the download as finished and filesaved event is
raised decrease the thread counter.

Once you removed the last item of arraylist terminate
while cycle.

Kind Regards
Jorge
-----Original Message-----
I have a situation where I need to download multiple files in a vb.netapplication.

To speed up the process, I am trying to download multiple files at onetime looping through each of the files and launching them in their ownthread (code below). The problem is that when there are hundreds offiles to download, it launches them all at the same time and halfdon't get downloaded. Any idea how I could control it to launch say 4at a time, so that when one finished another would launch until thebatch is complete? Was thinking message queues but am not sure if thisis the right path to take.

Any help is appreciated
Dim count As Integer
'loop through each file
For count = CType(txturlcountbegin.Text, Integer) ToCType(txturlcountend.Text, Integer)
' create new download object
Dim c As Common = New Common
' Hoook up the on download complete event
AddHandler c.FileDownloaded, AddressOf filesaved 'Set the file download properties
c.fn = txtFileName.Text
c.sp = txtSavePath.Text
c.wc = txtWildCard.Text
c.tb = txtBegin.Text
c.te = txtEnd.Text
c.url = Regex.Replace(txtURL.Text, txtURLWILDCARD.Text,count.ToString)
c.batchnum = count
'launch a new thread to download the files
Dim t As New Thread(New ThreadStart (AddressOf c.getFiles)) t.Start()
Next
.

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jon Sequeira | last post by:
I'm have a class that represents shipping cost data for a commerce web site. The underlying data may only change once a month, maybe less, so I'd rather not hit the database every time the class is...
0
by: Dominik | last post by:
I am writing application which must download multiple files simultaneous. Initially I wanted to use multiple threads to achieve this task but later I heard that Net is "using" separate thread from...
6
by: Quiet Man | last post by:
Hi all, I'm designing a fairly simple service that will run on W2K/SP4 and W2K3 servers. It's job is to be a very specialized database server that listens on a given IP address / TCP port and...
2
by: Alex | last post by:
Dear colleagues I am programming an application which starts a lot of threads for some calculations. The problem that I have is that when I start up to 100 threads then everything works fine....
6
by: cj | last post by:
As many of you know I'm writing a TCP/IP server with multiple threads handling multiple short conversations (submit a short string, send back a sort string). Threads are created as needed to...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
2
by: Tobiah | last post by:
I have a class that I call Borg that starts like this: class Borg(dict): static_state = {} def __init__(self): self.__dict__ = self.static_state so that I can access the same data from...
4
by: raylopez99 | last post by:
Compound question: first, and this is not easy, if there's a way to detect multiple simultaneous key presses in C# let me know (in the below code, keys c and d being pressed simultaneously or...
0
by: SteelNetNob | last post by:
I am having a problem where I have a COM application that can be run stand-alone and programatically via COM interop. If an instance of the COM application is being run when my .NET application that...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.