Monitoring threads and accessing a shared variable

  • Thread starter Thread starter Jon C
  • Start date Start date
J

Jon C

Hi,

I've written a multi-threaded web spider which stores search results in
a Shared ArrayList. Since each thread can launch further threads, the
problem I have is pausing my main sub until all the threads have
terminated, then accessing the ArrayList.

Thanks for your help

Jon
 
Hi Jon,
The main thread starts one thread first, and that thread may result in
several further threads, right?
I think you could use an Int32 value as a counter. Each lauched thread
increment the counter using Interlocked.Increment method. The main
thread will poll every short interval to see if counter is rezo then
accessing the ArrayList. The array list could be accessed by many
threads at a time, so I guess you should get it via
ArrayList.Synchronized method.
Regards,
Thi
 
Back
Top