protected static void OnWrite(IAsyncResult result) { if (!result.CompletedSynchronously) { MultiAsyncResult multiResult = (MultiAsyncResult)result.AsyncState; BaseWriter thisPtr = (BaseWriter)multiResult.Context; try { thisPtr._stream.EndWrite(result); multiResult.Leave(); } catch (Exception e) { multiResult.Leave(e); } } }
protected void Flush(MultiAsyncResult multiResult) { if (_bufferBuilder.Length > 0) { if (multiResult != null) { multiResult.Enter(); IAsyncResult result = _stream.BeginWrite(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length, s_onWrite, multiResult); if (result.CompletedSynchronously) { _stream.EndWrite(result); multiResult.Leave(); } } else { _stream.Write(_bufferBuilder.GetBuffer(), 0, _bufferBuilder.Length); } _bufferBuilder.Reset(); } }