using System;
using System.Threading;
public class Task {
[ThreadStatic]
static int id = 10;
public string threadName;
public void Run( string ThreadName ) {
this.threadName = ThreadName;
Thread T = new Thread( new ThreadStart( process ) );
T.Start( );
}
public void process( ) {
Console.WriteLine( "Thread {0} is running", threadName );
for(int i = 0; i < 10; i++ )
Console.WriteLine("Thread {0} : id = {1}", this.threadName, id++ );
}
}
public class MainClass {
public static void Main( ) {
Task t1 = new Task( );
Task t2 = new Task( );
t1.Run( "Worker 1" );
t2.Run( "Worker 2" );
Task t3 = new Task( );
t3.threadName = "Main Thread";
t3.process( );
}
}
|