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 ();}