MemoryStream.CopyToAsync(Stream, Int32, CancellationToken) 方法

定義

使用指定的緩衝區大小和取消語彙基元,以非同步的方式從目前資料流讀取所有位元組,並將其寫入另一個資料流。Asynchronously reads all the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

public:
 override System::Threading::Tasks::Task ^ CopyToAsync(System::IO::Stream ^ destination, int bufferSize, System::Threading::CancellationToken cancellationToken);
public override System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken);
override this.CopyToAsync : System.IO.Stream * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task

參數

destination
Stream

目前資料流的內容將複製到其中的資料流。The stream to which the contents of the current stream will be copied.

bufferSize
Int32

緩衝區的大小 (以位元組為單位)。The size, in bytes, of the buffer. 這個值必須大於零。This value must be greater than zero.

cancellationToken
CancellationToken

用來監視是否有取消要求的語彙基元。The token to monitor for cancellation requests.

傳回

表示非同步複製作業的工作。A task that represents the asynchronous copy operation.

例外狀況

destinationnulldestination is null.

buffersize 為負值或零。buffersize is negative or zero.

目前資料流或目的資料流已處置。Either the current stream or the destination stream is disposed.

目前資料流不支援讀取,或目的資料流不支援寫入。The current stream does not support reading, or the destination stream does not support writing.

適用於