UploadFileCompletedEventHandler デリゲートとは? わかりやすく解説

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

UploadFileCompletedEventHandler デリゲート

メモ : このデリゲートは、.NET Framework version 2.0新しく追加されたものです。

WebClient の UploadFileCompleted イベント処理するメソッド表します

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

Public Delegate Sub UploadFileCompletedEventHandler
 ( _
    sender As Object, _
    e As UploadFileCompletedEventArgs _
)
Dim instance As New UploadFileCompletedEventHandler(AddressOf
 HandlerMethod)
public delegate void UploadFileCompletedEventHandler
 (
    Object sender,
    UploadFileCompletedEventArgs e
)
public delegate void UploadFileCompletedEventHandler
 (
    Object^ sender, 
    UploadFileCompletedEventArgs^ e
)
/** @delegate */
public delegate void UploadFileCompletedEventHandler
 (
    Object sender, 
    UploadFileCompletedEventArgs e
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントソース

e

イベント データ格納している UploadFileCompletedEventArgs。

解説解説
使用例使用例

非同期的にファイルアップロードするコード例次に示します

'  Sample call: UploadFileInBackground("http:' www.contoso.com/fileUpload.aspx",
 "data.txt")
Public Shared Sub UploadFileInBackground(ByVal
 address As String, ByVal
 fileName As String)

    Dim waiter As System.Threading.AutoResetEvent
 = New System.Threading.AutoResetEvent(False)
    Dim client As WebClient = New
 WebClient()
    Dim method As String
 = "POST"
                 Dim uri as Uri =  New
 Uri(address)

    '  Specify that that UploadFileCallback method gets called
    '  when the file upload completes.
    AddHandler client.UploadFileCompleted, AddressOf
 UploadFileCallback
    client.UploadFileAsync(uri, method, fileName, waiter)

    '  Block the main application thread. Real applications
    '  can perform other tasks while waiting for the upload to complete.
    waiter.WaitOne()
    Console.WriteLine("File upload is complete.")
End Sub

// Sample call: UploadFileInBackground("http://www.contoso.com/fileUpload.aspx",
 "data.txt")
public static void UploadFileInBackground
 (string address, string fileName)
{
    System.Threading.AutoResetEvent waiter = new System.Threading.AutoResetEvent
 (false);
    WebClient client = new WebClient ();
    Uri uri = new Uri(address);
    string method = "POST";

    // Specify that that UploadFileCallback method gets called
    // when the file upload completes.
    client.UploadFileCompleted += new UploadFileCompletedEventHandler
 (UploadFileCallback);
    client.UploadFileAsync (uri, method, fileName, waiter);

    // Block the main application thread. Real applications
    // can perform other tasks while waiting for the upload to complete.
    waiter.WaitOne ();
    Console.WriteLine ("File upload is complete.");
}

アップロード完了する次のメソッド呼び出されます。

Public Shared Sub UploadFileCallback(ByVal
 sender As Object, ByVal
 e As System.Net.UploadFileCompletedEventArgs)

    Dim waiter As System.Threading.AutoResetEvent
 = CType(e.UserState, System.Threading.AutoResetEvent)
    Try

        Dim reply As String
 = System.Text.Encoding.UTF8.GetString(e.Result)
        Console.WriteLine(reply)
    Finally
        '  If this thread throws an exception, make sure that
        '  you let the main application thread resume.
        waiter.Set()
    End Try
End Sub

public static void UploadFileCallback
 (Object sender, UploadFileCompletedEventArgs e)
{
    System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;;
    try
    {
        string reply = System.Text.Encoding.UTF8.GetString (e.Result);

        Console.WriteLine (reply);
    }
    finally
    {
        // If this thread throws an exception, make sure that
        // you let the main application thread resume.
        waiter.Set ();
    }
}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「UploadFileCompletedEventHandler デリゲート」の関連用語

UploadFileCompletedEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



UploadFileCompletedEventHandler デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS