WebClient.UploadProgressChanged 이벤트

정의

비동기 업로드 작업을 통해 데이터 전체 또는 일부를 성공적으로 전송하면 발생합니다.

public:
 event System::Net::UploadProgressChangedEventHandler ^ UploadProgressChanged;
public event System.Net.UploadProgressChangedEventHandler? UploadProgressChanged;
public event System.Net.UploadProgressChangedEventHandler UploadProgressChanged;
member this.UploadProgressChanged : System.Net.UploadProgressChangedEventHandler 
Public Custom Event UploadProgressChanged As UploadProgressChangedEventHandler 
Public Event UploadProgressChanged As UploadProgressChangedEventHandler 

이벤트 유형

UploadProgressChangedEventHandler

예제

다음 코드 예제에서는이 이벤트에 대 한 이벤트 처리기를 설정 하는 방법을 보여 줍니다.

// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
void UploadFileInBackground2( String^ address, String^ fileName )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   client->UploadFileCompleted +=
     gcnew UploadFileCompletedEventHandler (UploadFileCallback2);

   // Specify a progress notification handler.
   client->UploadProgressChanged +=
       gcnew UploadProgressChangedEventHandler( UploadProgressCallback );
   client->UploadFileAsync( uri, "POST", fileName );
   Console::WriteLine( "File upload started." );
}
// Sample call: UploadFileInBackground2("http://www.contoso.com/fileUpload.aspx", "data.txt")
public static void UploadFileInBackground2(string address, string fileName)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    client.UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCallback2);

    // Specify a progress notification handler.
    client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
    client.UploadFileAsync(uri, "POST", fileName);
    Console.WriteLine("File upload started.");
}
'  Sample call: UploadFileInBackground2("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground2(ByVal address As String, ByVal fileName As String)

    Dim client As WebClient = New WebClient()
                Dim uri as Uri =  New Uri(address)
    AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback2

    '  Specify a progress notification handler.
    AddHandler client.UploadProgressChanged, AddressOf UploadProgressCallback
    client.UploadFileAsync(uri, "POST", fileName)
    Console.WriteLine("File upload started.")
End Sub

다음 코드 예제에서는이 이벤트에 대 한 처리기의 구현을 보여 있습니다.

static void UploadProgressCallback(Object^ sender,
          UploadProgressChangedEventArgs^ e)
      {
          // Displays the operation identifier, and the transfer progress.
          Console::WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...",
              (String ^)e->UserState,
              e->BytesSent,
              e->TotalBytesToSend,
              e->ProgressPercentage);
      }
static void DownloadProgressCallback(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);
      }
private static void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
{
    // Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...",
        (string)e.UserState,
        e.BytesSent,
        e.TotalBytesToSend,
        e.ProgressPercentage);
}
private static void DownloadProgressCallback(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);
}
Private Shared Sub UploadProgressCallback(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

    '  Displays the operation identifier, and the transfer progress.
    Console.WriteLine("{0}    uploaded {1} of {2} bytes. {3} % complete...", _
     CStr(e.UserState), e.BytesSent, e.TotalBytesToSend, e.ProgressPercentage)
End Sub
Private Shared Sub DownloadProgressCallback(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

설명

이 이벤트는 비동기 업로드가 진행될 때마다 발생합니다. 이 이벤트는 다음 방법 중에서 업로드를 시작할 때 발생합니다.

방법 설명
UploadDataAsync 호출 스레드를 Byte 차단하지 않고 배열을 리소스에 보냅니다.
UploadFileAsync 호출 스레드를 차단하지 않고 리소스에 로컬 파일을 보냅니다.
UploadValuesAsync 호출 스레드를 NameValueCollection 차단하지 않고 리소스에 보내고 응답이 포함된 배열을 반환 Byte 합니다.

UploadProgressChangedEventHandler 이벤트의 대리자입니다. 이 클래스는 UploadProgressChangedEventArgs 이벤트 처리기에 이벤트 데이터를 제공합니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상