WebClient.DownloadProgressChanged イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > WebClient.DownloadProgressChanged イベントの意味・解説 

WebClient.DownloadProgressChanged イベント

メモ : このイベントは、.NET Framework version 2.0 で新しく追加されたものです。

非同期ダウンロード操作で、データの一部またはすべてが正常に転送された場合に発生します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Event DownloadProgressChanged As
 DownloadProgressChangedEventHandler
Dim instance As WebClient
Dim handler As DownloadProgressChangedEventHandler

AddHandler instance.DownloadProgressChanged, handler
public event DownloadProgressChangedEventHandler DownloadProgressChanged
public:
event DownloadProgressChangedEventHandler^ DownloadProgressChanged {
    void add (DownloadProgressChangedEventHandler^ value);
    void remove (DownloadProgressChangedEventHandler^ value);
}
/** @event */
public void add_DownloadProgressChanged (DownloadProgressChangedEventHandler
 value)

/** @event */
public void remove_DownloadProgressChanged
 (DownloadProgressChangedEventHandler value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

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

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

イベント処理の詳細については、「イベントの利用」を参照してください。

internal class MyWebClient:WebClient{
        protected override WebRequest GetWebRequest(Uri address) {
            FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
            req.UsePassive = false;
            return req;
        }
    }
使用例使用例

このイベントのイベント ハンドラを設定するコード例を次に示します。

'  Sample call : DownLoadFileInBackground2 ("http:' www.contoso.com/logs/January.txt")
Public Shared Sub DownLoadFileInBackground2(ByVal
 address As String)

    Dim client As WebClient = New
 WebClient()

    '  Specify that the DownloadFileCallback method gets called
    '  when the download completes.
    AddHandler client.DownloadFileCompleted, AddressOf
 DownloadFileCallback2
    '  Specify a progress notification handler.
    AddHandler client.DownloadProgressChanged, AddressOf
 DownloadProgressCallback
                Dim uri as Uri = New
 Uri(address)
    client.DownloadFileAsync(uri, "serverdata.txt")
End Sub

// Sample call : DownLoadFileInBackground2 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground2
 (string address)
{
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);

    // Specify that the DownloadFileCallback method gets called
    // when the download completes.
    client.DownloadFileCompleted += new AsyncCompletedEventHandler
 (DownloadFileCallback2);
    // Specify a progress notification handler.
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
    client.DownloadFileAsync (uri, "serverdata.txt");
}

このイベントのハンドラの実装を次のコード例に示します。

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
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
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);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「WebClient.DownloadProgressChanged イベント」の関連用語

WebClient.DownloadProgressChanged イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebClient.DownloadProgressChanged イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS