DownloadProgressChangedEventHandler Delegate

Definition

Represents the method that will handle the DownloadProgressChanged event of a WebClient.

public delegate void DownloadProgressChangedEventHandler(System::Object ^ sender, DownloadProgressChangedEventArgs ^ e);
public delegate void DownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e);
type DownloadProgressChangedEventHandler = delegate of obj * DownloadProgressChangedEventArgs -> unit
Public Delegate Sub DownloadProgressChangedEventHandler(sender As Object, e As DownloadProgressChangedEventArgs)

Parameters

sender
Object

The source of the event.

Examples

The following code example demonstrates setting an event handler for the DownloadProgressChanged event.

// Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
void DownLoadFileInBackground4( String^ address )
{
   WebClient^ client = gcnew WebClient;
   Uri ^uri = gcnew Uri(address);

   // Specify a DownloadFileCompleted handler here...

   // Specify a progress notification handler.
   client->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler( DownloadProgressCallback4 );
   
   client->DownloadFileAsync( uri, "serverdata.txt" );
}

static void DownloadProgressCallback4(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);
}
// Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
public static void DownLoadFileInBackground4(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(address);

    // Specify a DownloadFileCompleted handler here...

    // Specify a progress notification handler.
    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback4);

    client.DownloadFileAsync(uri, "serverdata.txt");
}

private static void DownloadProgressCallback4(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);
}
' Sample call : DownLoadFileInBackground4 ("http://www.contoso.com/logs/January.txt");
Public Shared Sub DownLoadFileInBackground4(ByVal address As String)

    Dim client As WebClient = New WebClient()

    ' Specify a DownloadFileCompleted handler here...

    '  Specify a progress notification handler.
    AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressCallback4

    Dim uri as Uri = New Uri(address)
    client.DownloadFileAsync(uri, "serverdata.txt")

End Sub

Private Shared Sub DownloadProgressCallback4(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

Remarks

When you create a DownloadProgressChangedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Handling and Raising Events.

Note

If the server does not send the size of the downloaded file (such as in the case of a passive FTP connection), ProgressPercentage may always be zero.

Extension Methods

GetMethodInfo(Delegate)

Gets an object that represents the method represented by the specified delegate.

Applies to