C # Multithread operation example,

Source: Internet
Author: User

C # Multithread operation example,

 

Using System; using System. threading; // reference multithreading namespace ThreadTest {public class Alpha {public void Beta () {while (true) {Console. writeLine ("Alpha. beta is running in its own thread. ") ;}}; public class Simple {public static int Main () {Console. writeLine ("Thread Start/Stop/Join Sample"); Alpha oAlpha = new Alpha (); // file: // create a Thread to execute Beta () of the Alpha Class () method Thread oThread = new Thread (new ThreadSta Rt (oAlpha. Beta); oThread. Start (); while (! OThread. isAlive) Thread. sleep (1); oThread. abort (); oThread. join (); Console. writeLine (); Console. writeLine ("Alpha. beta has finished "); try {Console. writeLine ("Try to restart the Alpha. beta thread "); oThread. start ();} catch (ThreadStateException) {Console. write ("ThreadStateException trying to restart Alpha. beta. "); Console. writeLine ("Expected since aborted threads cannot be restarted. "); Console. readLine () ;}return 0 ;}}}

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.