UnmanagedMemoryStream.ReadAsync UnmanagedMemoryStream.ReadAsync UnmanagedMemoryStream.ReadAsync Method

定義

多載

ReadAsync(Memory<Byte>, CancellationToken) ReadAsync(Memory<Byte>, CancellationToken)

以非同步方式將非受控記憶體資料流位元組讀入記憶體區域。Asynchronously reads the unmanaged memory stream bytes into the memory region.

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

將指定的位元組數以非同步方式讀入指定的陣列。Asynchronously reads the specified number of bytes into the specified array.

ReadAsync(Memory<Byte>, CancellationToken) ReadAsync(Memory<Byte>, CancellationToken)

以非同步方式將非受控記憶體資料流位元組讀入記憶體區域。Asynchronously reads the unmanaged memory stream bytes into the memory region.

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

參數

buffer
Memory<Byte>

當這個非同步方法完成時,此記憶體區域會包含從非受控記憶體資料流讀取的所有位元組。When the asynchronous method finishes, this memory region contains all the bytes read from the unmanaged memory stream.

cancellationToken
CancellationToken CancellationToken CancellationToken

用來監視是否有取消要求的語彙基元。The token to monitor for cancellation requests. 預設值為 NoneThe default value is None.

傳回

表示非同步讀取作業並會將位元組總數包裝到緩衝區的工作。A task that represents the asynchronous read operation, and wraps the total number of bytes read into the buffer.

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

將指定的位元組數以非同步方式讀入指定的陣列。Asynchronously reads the specified number of bytes into the specified array.

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>

參數

buffer
Byte[]

寫入資料的緩衝區。The buffer to write the data into.

offset
Int32 Int32 Int32

開始於此處自資料流寫入資料的 buffer 中的位元組位移。The byte offset in buffer at which to begin writing data from the stream.

count
Int32 Int32 Int32

要讀取的最大位元組數。The maximum number of bytes to read.

cancellationToken
CancellationToken CancellationToken CancellationToken

用來監視是否有取消要求的語彙基元。The token to monitor for cancellation requests. 預設值為 NoneThe default value is None.

傳回

表示非同步讀取作業的工作。A task that represents the asynchronous read operation. TResult 參數的值會包含讀取至緩衝區的位元組總數。The value of the TResult parameter contains the total number of bytes read into the buffer. 如果目前可供使用的位元組數目少於所要求的數目,結果值可能會小於所要求的位元組數目,或者如果已經到達資料流末端,則可能為 0 (零)。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.

備註

如果在讀取作業期間發生例外狀況, 則會將它設定為Task.Exception所傳回工作之屬性的。If an exception occurs during the read operation, it will be set as the Task.Exception of the property of the returned task.

適用於