public int EndRead(IAsyncResult itfAR) { if (itfAR == null) { throw new ArgumentNullException("AsyncResult cannot be null"); } if (!(itfAR is CanAsyncResult)) { throw new ArgumentException("AsyncResult object was not created by calling BeginRead on this class."); } CanAsyncResult result = (CanAsyncResult)itfAR; try { if (!result.IsCompleted) { result.AsyncWaitHandle.WaitOne(); } if (result.Error != null) { throw new USBException("Asynchronous read from pipe has failed.", result.Error); } return(result.MessageTransfered); } finally { result.Dispose(); } }
public IAsyncResult BeginRead(CanMessage[] frames, int offset, int length, AsyncCallback userCallback, object stateObject) { if (!IsConnected) { throw new CanAdapterException("Adapter is Disconnected. Code:-8604."); //Doc } if (!_isOpen) { throw new CanAdapterException("Bus is Closed. Code:-8605"); //Doc } if (frames == null) { throw new ArgumentNullException("Frame Buffer cannot be null. Code:-8606."); //Doc } _readBeginFrameArray = frames; _readBeginLength = length; _readBeginOffset = offset; _asyncReadBeginResult = new CanAsyncResult(userCallback, stateObject); try { //Van annyi elem, hogy most azonnal vége legyen. if (IncomingMsgQueue.Count >= length) { Read(_readBeginFrameArray, offset, length); _asyncReadBeginResult.OnCompletion(true, null, length, true); } } catch (Exception) { _asyncReadBeginResult.Dispose(); throw; } return(_asyncReadBeginResult); }