C#异步操作sample1

NamedPipeServerStream pipe; 
ManualResetEvent WriteFlag; 
//initialise pipe 
lock (pipe) 
{ 
   
//I wish this method existed 
   
WaitHandle NewDataHandle = pipe.GetDataAvailableWaithandle(); 
   
Waithandle[] BreakConditions = new Waithandle[2]; 
   
BreakConditions[0] = NewDataHandle; 
   
BreakConditions[1] = WriteFlag; 
   
int breakcode = WaitHandle.WaitAny(BreakConditions); 
   
switch (breakcode) 
   
{ 
       
case 0: 
           
//do a read on the pipe 
           
break; 
       
case 1: 
           
//break so that we release the lock on the pipe 
           
break; 
     
} 
} 

原文地址:https://www.cnblogs.com/kevinzhwl/p/3878905.html