MemoryStream.ReadAsync Método
Definição
Sobrecargas
ReadAsync(Memory<Byte>, CancellationToken) |
Lê de forma assíncrona uma sequência de bytes do fluxo de memória atual, grava a sequência no |
ReadAsync(Byte[], Int32, Int32, CancellationToken) |
Lê de forma assíncrona uma sequência de bytes do fluxo atual, avança a posição no fluxo até o número de bytes lidos e monitora as solicitações de cancelamento.Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests. |
ReadAsync(Memory<Byte>, CancellationToken)
Lê de forma assíncrona uma sequência de bytes do fluxo de memória atual, grava a sequência no destination
, avança a posição no fluxo de memória até o número de bytes lidos e monitora as solicitações de cancelamento.Asynchronously reads a sequence of bytes from the current memory stream, writes the sequence into destination
, advances the position within the memory stream by the number of bytes read, and monitors cancellation requests.
public override System.Threading.Tasks.ValueTask<int> ReadAsync (Memory<byte> destination, System.Threading.CancellationToken cancellationToken = null);
override this.ReadAsync : Memory<byte> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Parâmetros
A região da memória na qual gravar os dados.The region of memory to write the data into.
- cancellationToken
- CancellationToken
O token a se monitorar para solicitações de cancelamento.The token to monitor for cancellation requests. O valor padrão é None.The default value is None.
Retornos
Uma tarefa que representa a operação de leitura assíncrona.A task that represents the asynchronous read operation. O valor de sua propriedade Result contém o número total de bytes lidos no destination
.The value of its Result property contains the total number of bytes read into the destination
. O valor do resultado poderá ser menor que o número de bytes alocados no destination
se esses muitos bytes não estiverem disponíveis no momento ou poderá ser zero (0) se o final do fluxo de memória tiver sido atingido.The result value can be less than the number of bytes allocated in destination
if that many bytes are not currently available, or it can be 0 (zero) if the end of the memory stream has been reached.
ReadAsync(Byte[], Int32, Int32, CancellationToken)
Lê de forma assíncrona uma sequência de bytes do fluxo atual, avança a posição no fluxo até o número de bytes lidos e monitora as solicitações de cancelamento.Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
public:
override System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <System::Byte> ^ buffer, int offset, int count, System::Threading::CancellationToken cancellationToken);
[System.Runtime.InteropServices.ComVisible(false)]
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>
Parâmetros
- buffer
- Byte[]
O buffer no qual os dados serão gravados.The buffer to write the data into.
- offset
- Int32
O deslocamento de bytes no buffer
no qual será iniciada a gravação de dados no fluxo.The byte offset in buffer
at which to begin writing data from the stream.
- count
- Int32
O número máximo de bytes a serem lidos.The maximum number of bytes to read.
- cancellationToken
- CancellationToken
O token a se monitorar para solicitações de cancelamento.The token to monitor for cancellation requests. O valor padrão é None.The default value is None.
Retornos
Uma tarefa que representa a operação de leitura assíncrona.A task that represents the asynchronous read operation. O valor do parâmetro TResult
contém o número total de bytes lidos no buffer.The value of the TResult
parameter contains the total number of bytes read into the buffer. O valor do resultado poderá ser menor que o número de bytes solicitados se o número de bytes disponíveis no momento for menor que o número solicitado ou poderá ser 0 (zero) se o final do fluxo foi atingido.The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
- Atributos
Exceções
buffer
é null
.buffer
is null
.
offset
ou count
é negativo.offset
or count
is negative.
A soma de offset
e count
é maior que o tamanho do buffer.The sum of offset
and count
is larger than the buffer length.
Não há suporte para leitura no fluxo.The stream does not support reading.
O fluxo foi descartado.The stream has been disposed.
O fluxo está sendo usado no momento por uma operação de leitura anterior.The stream is currently in use by a previous read operation.
Comentários
Se a operação for cancelada antes de ser concluída, a tarefa retornada conterá o valor Canceled para a propriedade Status.If the operation is canceled before it completes, the returned task contains the Canceled value for the Status property.
Você pode criar um token de cancelamento criando uma instância da classe CancellationTokenSource e passando a propriedade Token como o parâmetro cancellationToken
.You can create a cancellation token by creating an instance of the CancellationTokenSource class and passing the Token property as the cancellationToken
parameter.