using System;
using System.Threading;
class MainClass
{
private static int ThreadCount = 5;
public static void DoCount()
{
for ( int i = 0; i < 3; i++ )
{
System.Console.WriteLine( "{0} reached {1}", Thread.CurrentThread.Name, i );
}
}
[STAThread]
static void Main(string[] args)
{
Thread[] t = new Thread[ ThreadCount ];
for( int k = 0; k < ThreadCount; k++ )
{
t[ k ] = new Thread( new ThreadStart( DoCount ) );
t[ k ].Name = "Thread " + k;
t[ k ].Start();
}
// wait for all the Threads to finish
for( int k = 0; k < ThreadCount; k++ )
{
t[ k ].Join();
}
}
}
|