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 

イベントの種類

次のコード例では、このイベントのイベント ハンドラーを設定する方法を示します。

// 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

注釈

このイベントは、非同期アップロードが進行するたびに発生します。 このイベントは、次のいずれかの方法を使用してアップロードを開始すると発生します。

Method 説明
UploadDataAsync 呼び出し元の Byte スレッドをブロックせずに、配列をリソースに送信します。
UploadFileAsync 呼び出し元のスレッドをブロックせずに、ローカル ファイルをリソースに送信します。
UploadValuesAsync NameValueCollectionをリソースに送信し、呼び出し元のスレッドをByteブロックせずに、応答を含む配列を返します。

UploadProgressChangedEventHandlerは、このイベントのデリゲートです。 クラスは UploadProgressChangedEventArgs 、イベント データをイベント ハンドラーに提供します。

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

適用対象