WebClient.DownloadProgressChanged 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
비동기 다운로드 작업을 통해 데이터 전체 또는 일부를 성공적으로 전송하면 발생합니다.
public:
event System::Net::DownloadProgressChangedEventHandler ^ DownloadProgressChanged;
public event System.Net.DownloadProgressChangedEventHandler? DownloadProgressChanged;
public event System.Net.DownloadProgressChangedEventHandler DownloadProgressChanged;
member this.DownloadProgressChanged : System.Net.DownloadProgressChangedEventHandler
Public Custom Event DownloadProgressChanged As DownloadProgressChangedEventHandler
Public Event DownloadProgressChanged As DownloadProgressChangedEventHandler
이벤트 유형
예제
다음 코드 예제에 대 한 이벤트 처리기를 설정 하는 방법을 보여 줍니다는 DownloadProgressChanged
이벤트입니다.
// Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
void DownLoadFileInBackground4( String^ address )
{
WebClient^ client = gcnew WebClient;
Uri ^uri = gcnew Uri(address);
// Specify a DownloadFileCompleted handler here...
// Specify a progress notification handler.
client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler( DownloadProgressCallback4 );
client->DownloadFileAsync( uri, "serverdata.txt" );
}
static void DownloadProgressCallback4(Object^ sender, DownloadProgressChangedEventArgs^ e)
{
// Displays the operation identifier, and the transfer progress.
Console::WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...",
(String ^)e->UserState,
e->BytesReceived,
e->TotalBytesToReceive,
e->ProgressPercentage);
}
// Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground4(string address)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
// Specify a DownloadFileCompleted handler here...
// Specify a progress notification handler.
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback4);
client.DownloadFileAsync(uri, "serverdata.txt");
}
private static void DownloadProgressCallback4(object sender, DownloadProgressChangedEventArgs e)
{
// Displays the operation identifier, and the transfer progress.
Console.WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...",
(string)e.UserState,
e.BytesReceived,
e.TotalBytesToReceive,
e.ProgressPercentage);
}
' Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
Public Shared Sub DownLoadFileInBackground4(ByVal address As String)
Dim client As WebClient = New WebClient()
' Specify a DownloadFileCompleted handler here...
' Specify a progress notification handler.
AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressCallback4
Dim uri as Uri = New Uri(address)
client.DownloadFileAsync(uri, "serverdata.txt")
End Sub
Private Shared Sub DownloadProgressCallback4(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
' Displays the operation identifier, and the transfer progress.
Console.WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...", _
CStr(e.UserState), e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage)
End Sub
설명
이 이벤트는 비동기 다운로드가 진행될 때마다 발생합니다. 이 이벤트는 다음 방법 중에서 다운로드를 시작할 때 발생합니다.
방법 | 설명 |
---|---|
DownloadDataAsync | 호출 스레드를 차단하지 않고 리소스에서 데이터를 다운로드하고 배열을 반환 Byte 합니다. |
DownloadFileAsync | 호출 스레드를 차단하지 않고 리소스에서 로컬 파일로 데이터를 다운로드합니다. |
OpenReadAsync | 호출 스레드를 차단하지 않고 리소스에서 데이터를 반환합니다. |
는 DownloadProgressChangedEventHandler 이 이벤트의 대리자입니다. 클래스는 DownloadProgressChangedEventArgs 이벤트 처리기에 이벤트 데이터를 제공합니다.
이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.
참고
수동 FTP 파일 전송은 서버가 파일 크기를 보내지 않았기 때문에 항상 진행률 0을 표시합니다. 진행률을 표시하려면 가상 메서드를 재정의하여 FTP 연결을 활성으로 GetWebRequest(Uri) 변경할 수 있습니다.
internal class MyWebClient : WebClientProtocol
{
protected override WebRequest GetWebRequest(Uri address)
{
FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
req.UsePassive = false;
return req;
}
}
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기