Multi thread

  • Thread starter Thread starter ruso
  • Start date Start date
R

ruso

I am searching some string in files in the folders. But i want to
search them with multithread form example 5 threads at the same time
how can i do thanks
 
Hi,

You can use several ways, onbe way is to have a queue with the files to be
processed, ( you can use a sync. queue, well you MUST ! really ) then you
create the X threads that get the file from the queue, you will have to keep
the results in an arraylist or something like that ( also must be sync to
avoid problems )

That's pretty much what you need I think , just post back if yuo need more
help,

Cheers,
 
ruso,

What I would do is use the ThreadPool class. This will allow you to
call a method which takes one parameter of type object (through the
WaitCallback delegate). You would then call the QueueUserWorkItem method,
passing the directories to the method that you want to be processed. This
would allow you to queue the requests, and let the ThreadPool allocate the
threads accordingly.

Hope this helps.
 
I think you will find in the end that using multithreads (unless you have a
multi-disks your searching and/or multi-cpus) will be slower then doing this
serial. Why? Because you will be stoping the progress of one thread to
start/finish progress on another. You will also be jumping the drive around
instead of just reading a to b. However if you just want to use threads for
learning, then others have posted info to help. If you do try it both ways,
please post the results. Cheers!
 
Back
Top