I have an application with one main thread and N worker threads. At some point I need that the main thread waits until all the N threads have completed one section of their work.
I normally would use Monitor.Wait() and Monitor.Pulse() but this will prevent the N threads from working at the same time.
Any idea on how to do that?
Thanks in advance.
Ok, what I’m doing now (using your ideas) and seems to work is this:
I declared a list of ManualResetEvent:
The process accepts incoming Tcp connections and starts one thread on each connection. So at the new client handler I’ve added this code:
The last thing done is to modify the Stop method to be sure that the Stop operation will not done with any thread inside the NonStoppableMethod:
I’m not sure that this is done in a right way because it’s the first time I deal with things like that. Do you feel that this is ok and is a good approach?
Thanks to all, mates!