threed thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i'am programming an application that launches 5 threads, those launches 10
threads more
i need that the last one 10 threads finished first, and then the others.

Any idea??

PD My english is not perfect but i have tried it.

Thank you
 
Jon said:
I'm not entirely sure what you mean, but Thread.Join might be what
you're after.

See http://www.pobox.com/~skeet/csharp/threads more general threading
information.

If you want to wait for all threads, using a WaitAll method, you could
do something like this:

/Joakim

using System;
using System.Threading;

public class App
{
public static void Main()
{
// Create worker threads
ThreadPool.SetMinThreads(10, 0);
ManualResetEvent[] events = new ManualResetEvent[10];
for(int i=0; i<10; i++)
{
events = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(
new WaitCallback(ThreadProc), events);
}
WaitHandle.WaitAll(events);
}

public static void ThreadProc(object state)
{
ManualResetEvent ev = (ManualResetEvent)state;
try
{
// Replace this with your working code...
}
finally
{
ev.Set();
}
}
}
 
Back
Top