April 10th, 2012, 02:31 AM
Multi thread file import/process
I was wondering if someone had an example of a basic multi threaded file processing?
For example, I have a stringlist of 10 file names, and I want to process each one in a thread, exclusive reading so that no one can open/process the same file while I am.
I also want to limit the total number of threads to 4 at a time until all the files have been processed.
What you need is a pair of class. One class act as threads manager and the other is the file processing thread itself. The main functionalities of the thread manager are:
- Provide thread safe way for the processing thread to get next file to process.
- To spawn new processing thread when new file is added and the number of the running thread is below maximum.