C # multi-thread usage 8-collaboration between threads AutoResetEvent,

Source: Internet
Author: User

C # multi-thread usage 8-collaboration between threads AutoResetEvent,

AutoResetEvent automatically resets the event, which is relative to ManualResetEvent. It is also used for inter-thread synchronization. For more information, see C # multi-thread usage 7-collaboration between threads ManualResetEvent.

Private static void MultiThreadSynergicWithAutoResetEvent () {// automatic notification method for Thread synchronization AutoResetEvent are = new AutoResetEvent (false); Thread thread1 = new Thread (() =>{ // The thread waits for an available notification at WaitOne first. waitOne (); // after the notification is received, the notification is automatically terminated and passed back. Therefore, the following is the code content of the thread operation Console. writeLine ("thread1 work"); // After the thread executes the necessary functions, it starts the notification again and passes the are. set () ;}); thread1.Start (); Thread thread2 = new Thread () =>{ are. waitOne (); Console. writeLine ("thread2 work") ;}); thread2.Start (); are. set ();}

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.