. Net multithreading note (3): thread status

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.