I need to download certain files using http://FTP.Already it is implemented without using the thread. It takes too much time to download all the files.
So i need to use some thread for speed up the process .
my code is like
foreach (string str1 in files)
{
download_FTP(str1)
}
I refer this , But i don’t want every files to be queued at ones.say for example 5 files at a time.
Okay, as you’re not using .NET 4 that makes it slightly harder – the Task Parallel Library would make it really easy to create five threads reading from a producer/consumer queue. However, it still won’t be too hard.
Queue<string>with all the files you want to downloadNote that as
Queue<T>isn’t thread-safe, you’ll need to lock to make sure that only one thread tries to fetch an item from the queue at a time:As noted elsewhere, threading may not speed things up at all – it depends where the bottleneck is. If the bottleneck is the user’s network connection, you won’t be able to get more data down the same size of pipe just by using multi-threading. On the other hand, if you have a lot of small files to download from different hosts, then it may be latency rather than bandwidth which is the problem, in which case threading will help.