thread status
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading; namespace multithreadtest {class program {static void main (string [] ARGs) {console. writeline ("begin thread 1"); thread thread1 = new thread (task); console. writeline ("start thread 1"); thread1.start (); printthreadstate (thread1); thread. sleep (3*1000); console. writeline ("suspend thread1"); thread1.suspend (); thread. sleep (1000); printthreadstate (thread1); console. writeline ("resume thread1"); thread1.resume (); printthreadstate (thread1); console. writeline ("Stop thread1"); thread1.abort (); thread. sleep (1000); printthreadstate (thread1); console. writeline ("begin thread 2"); thread thread2 = new thread (task2); thread2.start (); thread. sleep (2*1000); printthreadstate (thread2); thread. sleep (10*1000); printthreadstate (thread2); console. read ();} Private Static Void task () {console. writeline ("thread is running... "); While (true);} Private Static void task2 () {console. writeline ("thread start to sleep"); thread. sleep (10*1000); console. writeline ("thread was resumed");} Private Static void printthreadstate (thread) {console. writeline ("thread's status is: {0}", thread. threadstate. tostring ());}}}
Output