System.IO.FileStream.BeginRead C# (CSharp) Method

BeginRead() public method

public BeginRead ( byte array, int offset, int numBytes, AsyncCallback callback, object state ) : IAsyncResult
array byte
offset int
numBytes int
callback AsyncCallback
state object
return IAsyncResult
        public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback callback, object state)
        {
            if (array == null)
                throw new ArgumentNullException(nameof(array));
            if (offset < 0)
                throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
            if (numBytes < 0)
                throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_NeedNonNegNum);
            if (array.Length - offset < numBytes)
                throw new ArgumentException(SR.Argument_InvalidOffLen);

            if (IsClosed) throw new ObjectDisposedException(SR.ObjectDisposed_FileClosed);
            if (!CanRead) throw new NotSupportedException(SR.NotSupported_UnreadableStream);

            if (!IsAsync)
                return base.BeginRead(array, offset, numBytes, callback, state);
            else
                return TaskToApm.Begin(ReadAsyncInternal(array, offset, numBytes, CancellationToken.None), callback, state);
        }

Usage Example

Example #1
1
 public void BeginReadThrowsForWriteOnly()
 {
     using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
     {
         Assert.Throws<NotSupportedException>(() => fs.BeginRead(new byte[0], 0, 0, null, null));
     }
 }
All Usage Examples Of System.IO.FileStream::BeginRead