做串口测试的时候,发现断开硬件连接后发送数据一直无回应,故用此方法,等待指定的时间后做一些动作。
记录下,以后用的上。
public static bool isTimeOut(LS6827B_USB_CDC.TimeOutDelegate method,byte[] data) {
IAsyncResult rst= method.BeginInvoke(data,null,null);
if (rst.AsyncWaitHandle.WaitOne(new TimeSpan(0, 0, 1))) {
method.EndInvoke(rst);
return true;
}
else
{
return false;
}
}