C # New thread delay execution with multiple threads

Source: Internet
Author: User

  1. Using System;
  2. Using System. Threading;
  3.  
  4. Namespace ConsoleApplication1
  5. {
  6. Class Program
  7. {
  8. Public static ManualResetEvent mre = new ManualResetEvent (false );
  9.  
  10. Staticvoid Main (string [] args)
  11. {
  12. Thread newThread = new Thread (new ThreadStart (NewThread ));
  13. NewThread. Name = "New thread ";
  14. NewThread. Start ();
  15.  
  16. Mre. Set ();
  17.  
  18. Console. WriteLine ("the Main function ends. ");
  19. }
  20.  
  21. Staticvoid NewThread ()
  22. {
  23. Console. WriteLine ("New thread: waiting for an event ");
  24. Mre. WaitOne ();
  25. Console. WriteLine ("New thread: got an event ");
  26.  
  27. Console. WriteLine (DateTime. Now );
  28. Thread. Sleep (2000); // two seconds delayed
  29. Console. WriteLine (DateTime. Now );
  30.  
  31. Console. WriteLine ("the new thread has been executed .. ");
  32. Console. WriteLine ();
  33. }
  34. }
  35. }

Related Article

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.