473,598 Members | 3,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(txturlcou ntbegin.Text, Integer) To
CType(txturlcou ntend.Text, Integer)
' create new download object
Dim c As Common = New Common
' Hoook up the on download complete event
AddHandler c.FileDownloade d, AddressOf filesaved
'Set the file download properties
c.fn = txtFileName.Tex t
c.sp = txtSavePath.Tex t
c.wc = txtWildCard.Tex t
c.tb = txtBegin.Text
c.te = txtEnd.Text
c.url = Regex.Replace(t xtURL.Text, txtURLWILDCARD. Text,
count.ToString)
c.batchnum = count
'launch a new thread to download the files
Dim t As New Thread(New ThreadStart(Add ressOf c.getFiles))
t.Start()
Next
Nov 21 '05 #1
1 3431
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(txturlcou ntbegin.Text, Integer) ToCType(txturlco untend.Text, Integer)
' create new download object
Dim c As Common = New Common
' Hoook up the on download complete event
AddHandler c.FileDownloade d, AddressOf filesaved 'Set the file download properties
c.fn = txtFileName.Tex t
c.sp = txtSavePath.Tex t
c.wc = txtWildCard.Tex t
c.tb = txtBegin.Text
c.te = txtEnd.Text
c.url = Regex.Replace(t xtURL.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
1598
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 needed. My concerns are these: I want it to be thread-safe for any number of simultaneous sessions. I want it to be efficient-- is making one object available to potentially hundreds of simultaneous sessions an inefficient approach?
0
2671
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 ThradPool for each connection. What is the best (fastest) method to download multiple files from one server in .NET ???? (sorry for my english)
6
4429
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 handles multiple connections. Client programs will make a connection and pass text strings to the service, which will then return a value for each of the strings. It's unlikely the service will ever have more than 100 simultaneous connections and...
2
1760
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. Depending of number of jobs it might be that sometimes application need to start up to 4000 threads for this small jobs. You see probably already the problem. This is not good idea to start 5000 threads at the same time (memory). My idea is to...
6
5098
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 handle a new connection request and terminate after the exchange is complete. I got a new request for the program. I've been asked the the program write all the strings it receives and sends to a log file. I'm concerned about all these threads...
17
11856
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
2
1379
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 anywhere within
4
6459
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 nearly so). I researched this and for C# (as opposed to MFC) there is no library function, and no easy way, though some code on the net suggested that you set up a thread that 'lives' for a certain time, then, if keys are pressed in that certain...
0
1308
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 does the COM interop starts, it latches onto a currently running instance rather than making a new instance for itself. So here are the facts of my situation. I have a Delphi 7 app that implements a COM Server.
0
7985
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8389
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8263
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5848
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3896
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.