Stream.CopyToAsync 메서드
정의
현재 스트림에서 모든 바이트를 비동기적으로 읽어 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream.
오버로드
CopyToAsync(Stream, Int32, CancellationToken) |
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 버퍼 크기 및 취소 토큰을 사용하여 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. |
CopyToAsync(Stream, CancellationToken) |
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 취소 토큰을 사용하여 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token. |
CopyToAsync(Stream) |
현재 스트림에서 모든 바이트를 비동기적으로 읽어 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream. |
CopyToAsync(Stream, Int32) |
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 버퍼 크기로 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size. |
CopyToAsync(Stream, Int32, CancellationToken)
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 버퍼 크기 및 취소 토큰을 사용하여 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.
public:
virtual System::Threading::Tasks::Task ^ CopyToAsync(System::IO::Stream ^ destination, int bufferSize, System::Threading::CancellationToken cancellationToken);
public virtual System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, int bufferSize, System.Threading.CancellationToken cancellationToken);
abstract member CopyToAsync : System.IO.Stream * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.CopyToAsync : System.IO.Stream * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member CopyToAsync : System.IO.Stream * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.CopyToAsync : System.IO.Stream * int * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function CopyToAsync (destination As Stream, bufferSize As Integer, cancellationToken As CancellationToken) As 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. 이 값은 0보다 커야 합니다.This value must be greater than zero. 기본 크기는 81920입니다.The default size is 81920.
- cancellationToken
- CancellationToken
취소 요청을 모니터링할 토큰입니다.The token to monitor for cancellation requests. 기본값은 None입니다.The default value is None.
반환
비동기 복사 작업을 나타내는 작업입니다.A task that represents the asynchronous copy operation.
- 특성
예외
destination
이(가) null
인 경우destination
is null
.
buffersize
가 음수이거나 0인 경우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.
설명
CopyToAsync메서드를 사용 하면 주 스레드를 차단 하지 않고 리소스를 많이 사용 하는 i/o 작업을 수행할 수 있습니다.The CopyToAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. 이 성능 고려 사항은 특히 시간이 소비되는 스트림 작업이 UI 스레드를 차단하고 응용 프로그램이 작동하지 않는 것처럼 표시할 수 있는 Windows 8.x 스토어Windows 8.x Store 응용 프로그램 또는 데스크톱desktop 응용 프로그램에서 중요합니다.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. 비동기 메서드는 async
await
Visual Basic 및 c #의 및 키워드와 함께 사용 됩니다.The async methods are used in conjunction with the async
and await
keywords in Visual Basic and C#.
작업이 완료 되기 전에 취소 되는 경우 반환 된 작업에는 Canceled 속성에 대 한 값이 포함 됩니다 Status .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.
두 스트림 간의 복사 예는 오버 로드를 참조 하세요 CopyToAsync(Stream) .For an example of copying between two streams, see the CopyToAsync(Stream) overload.
적용 대상
CopyToAsync(Stream, CancellationToken)
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 취소 토큰을 사용하여 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token.
public:
System::Threading::Tasks::Task ^ CopyToAsync(System::IO::Stream ^ destination, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, System.Threading.CancellationToken cancellationToken);
member this.CopyToAsync : System.IO.Stream * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function CopyToAsync (destination As Stream, cancellationToken As CancellationToken) As Task
매개 변수
- destination
- Stream
현재 스트림의 내용을 복사할 스트림입니다.The stream to which the contents of the current stream will be copied.
- cancellationToken
- CancellationToken
취소 요청을 모니터링할 토큰입니다.The token to monitor for cancellation requests. 기본값은 None입니다.The 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. 이 성능 고려 사항은 특히 시간이 소비되는 스트림 작업이 UI 스레드를 차단하고 응용 프로그램이 작동하지 않는 것처럼 표시할 수 있는 Windows 8.x 스토어Windows 8.x Store 응용 프로그램 또는 데스크톱desktop 응용 프로그램에서 중요합니다.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. 비동기 메서드는 async
await
Visual Basic 및 c #의 및 키워드와 함께 사용 됩니다.The async methods are used in conjunction with the async
and await
keywords in Visual Basic and C#.
작업이 완료 되기 전에 취소 되는 경우 반환 된 작업에는 Canceled 속성에 대 한 값이 포함 됩니다 Status .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.
두 스트림 간의 복사 예는 오버 로드를 참조 하세요 CopyToAsync(Stream) .For an example of copying between two streams, see the CopyToAsync(Stream) overload.
적용 대상
CopyToAsync(Stream)
현재 스트림에서 모든 바이트를 비동기적으로 읽어 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream.
public:
System::Threading::Tasks::Task ^ CopyToAsync(System::IO::Stream ^ destination);
public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination);
member this.CopyToAsync : System.IO.Stream -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.CopyToAsync : System.IO.Stream -> System.Threading.Tasks.Task
Public Function CopyToAsync (destination As Stream) As Task
매개 변수
- destination
- Stream
현재 스트림의 내용을 복사할 스트림입니다.The stream to which the contents of the current stream will be copied.
반환
비동기 복사 작업을 나타내는 작업입니다.A task that represents the asynchronous copy operation.
- 특성
예외
destination
이(가) null
인 경우destination
is null
.
현재 스트림이나 대상 스트림이 삭제됩니다.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.
예제
다음 예제에서는 두 개체를 사용 하 여 FileStream 한 디렉터리에서 다른 디렉터리로 파일을 비동기적으로 복사 하는 방법을 보여 줍니다.The following example demonstrates how to use two FileStream objects to asynchronously copy the files from one directory to another. FileStream 클래스는 Stream 클래스에서 파생됩니다.The FileStream class derives from the Stream class. Click컨트롤에 대 한 이벤트 처리기는 Button async
비동기 메서드를 호출 하므로 한정자로 표시 됩니다.Notice that the Click event handler for the Button control is marked with the async
modifier because it calls an asynchronous method
using System;
using System.Threading.Tasks;
using System.Windows;
using System.IO;
namespace WpfApplication
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
string StartDirectory = @"c:\Users\exampleuser\start";
string EndDirectory = @"c:\Users\exampleuser\end";
foreach (string filename in Directory.EnumerateFiles(StartDirectory))
{
using (FileStream SourceStream = File.Open(filename, FileMode.Open))
{
using (FileStream DestinationStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf('\\'))))
{
await SourceStream.CopyToAsync(DestinationStream);
}
}
}
}
}
}
Imports System.IO
Class MainWindow
Private Async Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim StartDirectory As String = "c:\Users\exampleuser\start"
Dim EndDirectory As String = "c:\Users\exampleuser\end"
For Each filename As String In Directory.EnumerateFiles(StartDirectory)
Using SourceStream As FileStream = File.Open(filename, FileMode.Open)
Using DestinationStream As FileStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf("\"c)))
Await SourceStream.CopyToAsync(DestinationStream)
End Using
End Using
Next
End Sub
End Class
설명
CopyToAsync메서드를 사용 하면 주 스레드를 차단 하지 않고 리소스를 많이 사용 하는 i/o 작업을 수행할 수 있습니다.The CopyToAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. 이 성능 고려 사항은 특히 시간이 소비되는 스트림 작업이 UI 스레드를 차단하고 응용 프로그램이 작동하지 않는 것처럼 표시할 수 있는 Windows 8.x 스토어Windows 8.x Store 응용 프로그램 또는 데스크톱desktop 응용 프로그램에서 중요합니다.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. 비동기 메서드는 async
await
Visual Basic 및 c #의 및 키워드와 함께 사용 됩니다.The async methods are used in conjunction with the async
and await
keywords in Visual Basic and C#.
복사는 현재 스트림의 현재 위치에서 시작 됩니다.Copying begins at the current position in the current stream.
적용 대상
CopyToAsync(Stream, Int32)
현재 스트림에서 바이트를 비동기적으로 읽어 지정된 버퍼 크기로 다른 스트림에 씁니다.Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.
public:
System::Threading::Tasks::Task ^ CopyToAsync(System::IO::Stream ^ destination, int bufferSize);
public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, int bufferSize);
[System.Runtime.InteropServices.ComVisible(false)]
public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination, int bufferSize);
member this.CopyToAsync : System.IO.Stream * int -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.CopyToAsync : System.IO.Stream * int -> System.Threading.Tasks.Task
Public Function CopyToAsync (destination As Stream, bufferSize As Integer) As 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. 이 값은 0보다 커야 합니다.This value must be greater than zero. 기본 크기는 81920입니다.The default size is 81920.
반환
비동기 복사 작업을 나타내는 작업입니다.A task that represents the asynchronous copy operation.
- 특성
예외
destination
이(가) null
인 경우destination
is null
.
buffersize
가 음수이거나 0인 경우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.
설명
CopyToAsync메서드를 사용 하면 주 스레드를 차단 하지 않고 리소스를 많이 사용 하는 i/o 작업을 수행할 수 있습니다.The CopyToAsync method enables you to perform resource-intensive I/O operations without blocking the main thread. 이 성능 고려 사항은 특히 시간이 소비되는 스트림 작업이 UI 스레드를 차단하고 응용 프로그램이 작동하지 않는 것처럼 표시할 수 있는 Windows 8.x 스토어Windows 8.x Store 응용 프로그램 또는 데스크톱desktop 응용 프로그램에서 중요합니다.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. 비동기 메서드는 async
await
Visual Basic 및 c #의 및 키워드와 함께 사용 됩니다.The async methods are used in conjunction with the async
and await
keywords in Visual Basic and C#.
복사는 현재 스트림의 현재 위치에서 시작 됩니다.Copying begins at the current position in the current stream.
두 스트림 간의 복사 예는 오버 로드를 참조 하세요 CopyToAsync(Stream) .For an example of copying between two streams, see the CopyToAsync(Stream) overload.