IsolatedStorageFileStream.ReadAsync 方法

定义

重载

ReadAsync(Byte[], Int32, Int32, CancellationToken)

将字节从当前缓冲的 IsolatedStorageFileStream 对象异步复制到字节数组。Asynchronously copies bytes from the current buffered IsolatedStorageFileStream object to a byte array.

ReadAsync(Memory<Byte>, CancellationToken)

将字节从当前缓冲的 IsolatedStorageFileStream 对象异步复制到字节内存范围。Asynchronously copies bytes from the current buffered IsolatedStorageFileStream object to a byte memory range.

ReadAsync(Byte[], Int32, Int32, CancellationToken)

将字节从当前缓冲的 IsolatedStorageFileStream 对象异步复制到字节数组。Asynchronously copies bytes from the current buffered IsolatedStorageFileStream object to a byte array.

public:
 override System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ buffer, int offset, int count, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task<int> ReadAsync (byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken);
override this.ReadAsync : byte[] * int * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>

参数

buffer
Byte[]

数据写入的缓冲区。The buffer to write the data into.

offset
Int32

缓冲区中开始写入的偏移量。The offset in the buffer at which to begin writing.

count
Int32

要读取的最大字节数。The maximum number of bytes to read.

cancellationToken
CancellationToken

要监视的取消请求标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

表示异步读取操作的任务。A task that represents the asynchronous read operation. 它会包装读入 buffer 中的总字节数。It wraps the total number of bytes read into the buffer. 如果当前可用的字节数没有请求的字节数那么多,则总字节数可能小于请求的字节数;如果已到达流的末尾,则为零。This can be less than the number of bytes requested if that many bytes are not currently available, or zero if the end of the stream is reached.

注解

buffer 参数可以是 Buffer 类的实例,也可以是以下类型之一的数组: ByteSByteCharInt16Int32Int64UInt16UInt32UInt64SingleDoubleThe buffer parameter can be an instance of the Buffer class, or an array of one of the following types: Byte, SByte, Char, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, or Double.

如果读取操作成功,则流的当前位置将按读取的字节数提前。If the read operation is successful, the current position of the stream is advanced by the number of bytes read. 如果发生异常,则流的当前位置不变。If an exception occurs, the current position of the stream is unchanged.

ReadAsync 方法将 buffer 参数视为字节块,而不考虑它的实际类型。The ReadAsync method treats the buffer parameter as a block of bytes, regardless of its actual type. 同样,offsetcount 参数始终以字节为单位指定。Likewise, the offset and count parameters are always specified in bytes. 对于字节数组以外的 buffer 参数,这意味着元素索引或元素数必须乘以元素大小(以字节为单位),以便为 offsetcount形成正确的值。For buffer parameters other than byte arrays, this means that an element index or the number of elements must be multiplied by the element size in bytes to form a correct value for offset or count.

仅当到达流的末尾时,ReadAsync 方法才会返回零。The ReadAsync method will return zero only if the end of the stream is reached. 在所有其他情况下,ReadAsync 始终从流中读取至少一个字节,然后返回。In all other cases, ReadAsync always reads at least one byte from the stream before returning. 如果调用 ReadAsync后,IsolatedStorageFileStream 对象中没有可用数据,则该方法将会阻止,直到至少有一个字节的数据可以返回。If no data is available from the IsolatedStorageFileStream object upon a call to ReadAsync, the method will block until at least one byte of data can be returned.

ReadAsync(Memory<Byte>, CancellationToken)

将字节从当前缓冲的 IsolatedStorageFileStream 对象异步复制到字节内存范围。Asynchronously copies bytes from the current buffered IsolatedStorageFileStream object to a byte memory range.

public override System.Threading.Tasks.ValueTask<int> ReadAsync (Memory<byte> buffer, System.Threading.CancellationToken cancellationToken = default);
override this.ReadAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>

参数

buffer
Memory<Byte>

数据写入的缓冲区。The buffer to write the data into.

cancellationToken
CancellationToken

要监视的取消请求标记。The token to monitor for cancellation requests. 默认值是 NoneThe default value is None.

返回

表示异步读取操作的任务。A task that represents the asynchronous read operation. 它会包装读入 buffer 中的总字节数。It wraps the total number of bytes read into the buffer. 如果当前可用的字节数没有请求的字节数那么多,则总字节数可能小于请求的字节数;如果已到达流的末尾,则为零。This can be less than the number of bytes requested if that many bytes are not currently available, or zero if the end of the stream is reached.

适用于