System.Net.Cache.ForwardingReadStream.BeginRead C# (CSharp) Method

BeginRead() public method

public BeginRead ( byte buffer, int offset, int count, AsyncCallback callback, Object state ) : IAsyncResult
buffer byte
offset int
count int
callback AsyncCallback
state Object
return IAsyncResult
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, Object state) {
            if (Interlocked.Increment(ref m_ReadNesting) != 1) {
                throw new NotSupportedException(SR.GetString(SR.net_io_invalidnestedcall, "BeginRead", "read"));
            }

            try {

                if (m_ReadCallback == null) {
                    m_ReadCallback = new AsyncCallback(ReadCallback);
                }

                if (m_ShadowStreamIsDead && m_BytesToSkip == 0L) {
                    return m_OriginalStream.BeginRead(buffer, offset, count, callback, state);
                }
                else {
                    InnerAsyncResult userResult = new InnerAsyncResult(state, callback, buffer, offset, count);
                    if (m_BytesToSkip != 0L) {
                        InnerAsyncResult temp = userResult;
                        userResult = new InnerAsyncResult(temp, null, new byte[4096],
                                                          0, m_BytesToSkip < (long) buffer.Length? (int)m_BytesToSkip: buffer.Length);
                    }
                    IAsyncResult result = m_OriginalStream.BeginRead(userResult.Buffer, userResult.Offset, userResult.Count, m_ReadCallback, userResult);
                    if (result.CompletedSynchronously)
                    {
                        ReadComplete(result);
                    }
                    return userResult;
                }
            }
            catch {
                Interlocked.Decrement(ref m_ReadNesting);
                throw;
            }
        }