CountdownEvent handler = new CountdownEvent(100);
for (int i = 0; i < 100; i++)
{
var j = i;
ThreadPool.QueueUserWorkItem(_ =>
{
Console.WriteLine("thread " + j);
Thread.Sleep(1000); //wait 1 seconds to do something
handler.Signal();
});
}
handler.Wait();
Console.WriteLine("finished");