using System; using System.Threading; public class Test { private static void MyFunc(AutoResetEvent ev) { Thread.Sleep((int)(new Random().NextDouble() * 1000)); ev.Set(); } public static void Main() { AutoResetEvent[] evs = {new AutoResetEvent(false), new AutoResetEvent(false), new AutoResetEvent(false)}; Thread thread1 = new Thread(() => MyFunc(evs[0])); Thread thread2 = new Thread(() => MyFunc(evs[1])); Thread thread3 = new Thread(() => MyFunc(evs[2])); thread1.Start(); thread2.Start(); thread3.Start(); int winner = WaitHandle.WaitAny(evs); Console.WriteLine("The winner is thread{0}", winner + 1); } }