ThreadSafe and Efficient Data Processing

Joined
Feb 2, 2008
Messages
8
Programming Experience
5-10
I'm building a multithreaded program, and i'm trying to figure out the best way to go about passing data between them.

I'm not going to just be sending variables between them.. For that i can use monitoring and whatnot..

What i'm trying to do is: I want to take a list of domains that I have (Starting from a text file), and pass them through the different threads.. Grabbing a new domain whenever a thread is finished completing it's task. Would it be best to open a file on the main thread, and call a function to retrieve the next line.. Or is it smarter to use something like a datagrid/sql db/array to rotate through them.. Please let me know what you think.. I need them threadsafe and the cpu intensiveness very low.. Thank you in advance.
 
Sounds like a standard producer and consumer pattern where the interim threadsafed data structure is a Queue. One thread reads the file and produces (puts into the queue) and the other threads all consume the queue and do their work. Use the ThreadPool mechanism for the workers. Read up on thread safety of a Queue here: http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx
 
Ahh, Queue is looking pretty sweet.. Then i assume you can lock the queue up while retrieving data so you don't get any problems along the way.. I'll look more into it, appreciate it.. I would have never thought they were have a class for that.. Why did i stay with vb6 so long :O.. Too much on .net -- Thanks for your help..
 
Read the MSDN on thread safety and the synchronized wrapper.. Good to know youre keen to put VB6 behind you.. remember that notion when it comes to databases; discard everything you know and read the new ways..
 
Back
Top