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



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

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

   

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



WebClient.DownloadProgressChanged イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS