WebClient.OnDownloadFileCompleted(AsyncCompletedEventArgs) 方法

定义

引发 DownloadFileCompleted 事件。

protected:
 virtual void OnDownloadFileCompleted(System::ComponentModel::AsyncCompletedEventArgs ^ e);
protected virtual void OnDownloadFileCompleted (System.ComponentModel.AsyncCompletedEventArgs e);
abstract member OnDownloadFileCompleted : System.ComponentModel.AsyncCompletedEventArgs -> unit
override this.OnDownloadFileCompleted : System.ComponentModel.AsyncCompletedEventArgs -> unit
Protected Overridable Sub OnDownloadFileCompleted (e As AsyncCompletedEventArgs)

参数

e
AsyncCompletedEventArgs

包含事件数据的 AsyncCompletedEventArgs 对象。

示例

下面的代码示例演示此方法的实现,该方法可由派生自 WebClient的类进行自定义。

virtual void OnDownloadFileCompleted( System::ComponentModel::AsyncCompletedEventArgs ^ e ) override
{
   // Here you can perform any custom actions before the event is raised
   // and event handlers are called...
   WebClient::OnDownloadFileCompleted( e );

   // Here you can perform any post event actions...
}
protected  override void OnDownloadFileCompleted (System.ComponentModel.AsyncCompletedEventArgs e)
{
    // Here you can perform any custom actions before the event is raised
    // and event handlers are called...

    base.OnDownloadFileCompleted(e);

    // Here you can perform any post event actions...
}

注解

谨慎

WebRequestHttpWebRequestServicePointWebClient 已过时,不应将其用于新开发。 请改用 HttpClient

从此类继承的类可以重写此方法,以在发生 DownloadFileCompleted 事件时执行其他任务。

引发事件会通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件

OnDownloadFileCompleted 方法还允许派生类在不附加委托的情况下处理事件。 这是处理派生类中的事件的首选技术。

继承者说明

在派生类中重写 OnDownloadFileCompleted(AsyncCompletedEventArgs) 时,请务必调用基类的 OnDownloadFileCompleted(AsyncCompletedEventArgs) 方法,以便注册的委托接收事件。

适用于