C # Multithreading

Source: Internet
Author: User
  1. UsingSystem;
  2. UsingSystem. Collections. Generic;
  3. UsingSystem. text;
  4. UsingSystem. Threading;
  5. NamespaceThread exercises
  6. {
  7. ClassProgram
  8. {
  9. Static VoidMain (String[] ARGs)
  10. {
  11. Console. writeline ("Start a new thread named");
  12. Thread t =NewThread (NewThreadstart (threadproc ));
  13. T. Start ();
  14. For(IntI = 0; I <4; I ++)
  15. {
  16. Console. writeline ("Main thread :"+ I );
  17. Thread. Sleep (1000 );
  18. }
  19. Console. writeline ("Call the join function and wait until the next thread ends");
  20. // After the execution of the thread is completed, join will block the calling thread until a thread is terminated. This example is the next thread.
  21. T. Join ();
  22. Console. writeline ("Thread execution completed");
  23. }
  24. Public Static VoidThreadproc ()
  25. {
  26. For(IntI = 0; I <10; I ++)
  27. {
  28. Console. writeline ("Threadporc: {0 }", I );
  29. Thread. Sleep (1000 );// Specify the number of milliseconds for blocking the current process
  30. }
  31. }
  32. }
  33. }

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.