同時実行
テストとかに・・・。
class Program { static void Main( string[] args ) { for ( int i = 0; i < 10; i++ ) { var a = new A(); new Thread(a.Start).Start(); } Thread.Sleep( 1000 ); Console.WriteLine( "ready?" ); WHandle.Set(); Console.WriteLine( "go" ); while ( Count != 10 ) { Thread.Sleep( 10 ); Console.WriteLine( Count ); } Console.WriteLine("end"); } public static int Count=0; public static EventWaitHandle WHandle = new EventWaitHandle(false, EventResetMode.ManualReset); } class A { public void Start() { Thread.Sleep( 100 ); Console.WriteLine( Thread.CurrentThread.ManagedThreadId ); Program.WHandle.WaitOne(); Thread.Sleep( 100 ); Program.Count++; } }