Keywords:
Waithandle,
Encapsulate OS-specific objects waiting for exclusive access to shared resources.
Use this static method to block a thread until one or more synchronization objects receive signals.
Waitall: wait until all specified execution threads end and return.
Waitany, Which is returned after the end of any specified execution thread.
Autoresetevent,
This class indicates a local waiting for Processing Event. After a single waiting thread is released, the event will be automatically reset upon termination.
Manualresetevent
It is not automatically reset.
Example:
Autoresetevent event1 = new autoresetevent (false );
Autoresetevent event2 = new autoresetevent (false );
Autoresetevent event3 = new autoresetevent (false );
Public void use3childthreads ()
{
Thread vthread1 = new thread (New threadstart (Method1 ));
Thread vthread2 = new thread (New threadstart (method2 ));
Thread vthread3 = new thread (New threadstart (method3 ));
Autoresetevent [] veventinprogress = new autoresetevent [3];
{
Event1,
Event2,
Event3
}
Vthread1.start ();
Vthread2.start ();
Vthread3.start ();
Waithandle. waitany (veventinprogress );
// Continue code
}
Public void Method1 ()
{
Thread. Sleep (1000 );
Event1.set ();
}
Public void method2 ()
{
Thread. Sleep (2000 );
Event2.set ();
}
Public void method3 ()
{
Thread. Sleep (3000 );
Event3.set ();
}