Jon Skeet [C# MVP] wrote:
axxegfx <ax*****@discussions.microsoft.com> wrote:
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.
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[i] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(
new WaitCallback(ThreadProc), events[i]);
}
WaitHandle.WaitAll(events);
}
public static void ThreadProc(object state)
{
ManualResetEvent ev = (ManualResetEvent)state;
try
{
// Replace this with your working code...
}
finally
{
ev.Set();
}
}
}