Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.
- destination
- The stream to which the contents of the current stream will be copied.
- bufferSize
- The size, in bytes, of the buffer. This value must be greater than zero. The default size is 4096.
- cancellationToken
- The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.
A task that represents the asynchronous copy operation.
The Stream.CopyToAsync(Stream, int, System.Threading.CancellationToken) method enables you to perform resource-intensive I/O operations without blocking the main thread. This performance consideration is particularly important in a win8_appname_long app or desktop_appname app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.
If the operation is canceled before it completes, the returned task contains the System.Threading.Tasks.TaskStatus.Canceled value for the System.Threading.Tasks.Task.Status property.
Copying begins at the current position in the current stream.
For an example of copying between two streams, see the Stream.CopyToAsync(Stream) overload.