ManualResetEvent implementation asynchronous wait, over time not to do processing, continue to execute code down
(ManualResetEvent involves a task that a thread must complete before other threads do it)
1manualresetevent[] MRE =Newmanualresetevent[2];2 3mre[0] =NewManualResetEvent (false);4SHOPPINGBLL SPB =NewSHOPPINGBLL (mre[0], dict);5Thread THD1 =NewThread (NewThreadStart (SPB. Getgprice));6 THD1. Start ();7 8mre[1] =NewManualResetEvent (false);9FAREBLL PFB =NewFAREBLL (mre[1], dict);TenThread THD2 =NewThread (NewThreadStart (PFB. Getfareprice)); One THD2. Start (); A - //Pause 12s More than 12s, execute the code behind, no longer wait -WaitHandle.WaitAll (MRE,12000,false);
View Code
Getgprice method (similar to Getfareprice), call the ManualResetEvent's set () method to return the signal;
public void Getgalileprice () { try { // todo
}
catch
(Exception e) {}
finally
if (_mre! = null ) {_mre. Set ();
// Return to completion signal
View Code
Reference:
Http://www.cnblogs.com/li-peng/p/3291306.html
Http://www.cnblogs.com/springyangwc/archive/2011/10/12/2208991.html
Asynchronous Wait (ManualResetEvent