问题描述
我有一个初始化Webclient对象的类,该类具有DownloadProgressChanged
和DownloadFileCompleted
事件。表单可以启动此对象和下载。如果用户选择关闭表单,则表单也可以停止下载。
DownloadFileCompleted
事件处理函数还接受一个参数,filename来引发一个事件,然后表单类可以对其进行处理。我阅读了有关如何定义此类自定义处理程序函数的信息,因此我的代码如下所示:
AddHandler fileReader.DownloadFileCompleted,Sub(sender,e) download_complete(FileName)
AddHandler fileReader.DownloadProgressChanged,AddressOf Download_ProgressChanged
fileReader.DownloadFileAsync(New Uri(Address),ParentPath + FileName)
Private Sub download_complete(filename As String)
RaiseEvent DownloadDone(filename)
End Sub
我注意到,当用户关闭表单时,下载已停止,但是我仍然收到“下载完成”事件(我已经知道e.Cancelled = True
会附带该事件)
我的问题是,当我引发事件时,我想发送此信息,因此我的download_complete
Sub的内容类似于:
Private Sub download_complete(filename As String,e as AsyncCompletedEventArgs)
If e.Cancelled = True Then
RaiseEvent DownloadDone(filename,"CANCELLED")
Else
RaiseEvent DownloadDone(filename,"COMPLETE")
End If
End Sub
这样,我将能够在表单的事件处理程序方法中很好地处理以下过程。我找不到该方法的任何文档。有人可以帮我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)