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

定義

使用指定的緩衝區大小和取消語彙基元,以非同步方式從目前緩衝資料流讀取位元組,並將其寫入至另一個資料流。Asynchronously reads the bytes from the current buffered 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 buffered stream will be copied.

bufferSize
Int32

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

cancellationToken
CancellationToken

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

傳回

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

備註

CopyToAsync 方法可讓您執行耗用大量資源的 i/o 作業,而不會封鎖主執行緒。The CopyToAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. 這項效能考量對於 Windows 8.x 市集Windows 8.x Store 應用程式或 桌面desktop 應用程式而言特別重要,尤其是針對耗時的資料流作業可能會阻礙 UI 執行緒,使應用程式看起來像是停止運作的情況。This performance consideration is particularly important in a Windows 8.x 市集Windows 8.x Store app or 桌面desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. 非同步方法會與 Visual Basic 和C#中的 asyncawait 關鍵字搭配使用。The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

如果作業在完成前取消,則傳回的工作會包含 Status 屬性的 Canceled 值。If the operation is canceled before it completes, the returned task contains the Canceled value for the Status property.

從目前資料流程的目前位置開始複製。Copying begins at the current position in the current stream.

適用於