|
-
Feb 27th, 2011, 02:27 PM
#1
Thread Starter
New Member
Multithreading a for loop?
Hey guys I was wondering if somone one could point me in the right direction on this.
Basically I am making a proxy testing program. A user can supply a list of proxies to test. What i want to be able to do is have them be able to specify how many threads they want to run. Then have the program go through the list testing each one using the amount of threads supplied. Really not sure even where to start on this. Threadpooling?
any advice would be appreciated. thanks!
-
Feb 27th, 2011, 04:19 PM
#2
Re: Multithreading a for loop?
I'm Not sure witch version you have or witch version they included this code but
Code:
System.Threading.Tasks.Parallel.For()
seems to work for me in most cases.
-
Feb 27th, 2011, 08:28 PM
#3
Re: Multithreading a for loop?
I'm pretty sure you have to be targeting framework 4.0, which means VS2010, to have any of the Parallel stuff.
That will multithread a loop, but from the description, you want to make some specific number of threads available, so thread pooling certainly sounds like one option. However, you might find that it makes more sense to create your own threads and make something of your own pool. My concern would be that the thread pool might be a bit TOO efficient for effective testing. It might automatically adjust in ways that you wouldn't want.
My usual boring signature: Nothing
 
-
Feb 28th, 2011, 07:01 PM
#4
Re: Multithreading a for loop?
Using the ThreadPool sounds like the easiest option, although it's important to realise that the system will use ThreadPool threads for other things at various times. If you want to be absolutely sure that you are using a specific number of threads then you would have to create them yourself.
What you can do is create a list of data items, where each thread will process one data item at a time. You can then explicitly create and start a specific number of threads and use a method that contains a loop that will keep running until the list is empty. You can use an AutoResetEvent to signal when the list has been processed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|