VB中异步的问题,如果中止异步和异步出错时怎样处理。
Option Explicit
Event DownloadProgress(CurBytes As Long, MaxBytes As Long, SaveFile As String)
Event DownloadError(SaveFile As String)
Event DownloadComplete(MaxBytes As Long, SaveFile As String)
Public downStat As Boolean
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
On Error Resume Next
Dim f() As Byte, fn As Long
If AsyncProp.BytesMax <> 0 Then
fn = FreeFile
f = AsyncProp.Value
Open AsyncProp.PropertyName For Binary Access Write As #fn
Put #fn, , f
Close #fn
Else
RaiseEvent DownloadError(AsyncProp.PropertyName)
End If
RaiseEvent DownloadComplete(CLng(AsyncProp.BytesMax), AsyncProp.PropertyName)
downStat = False
End Sub
Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty)
On Error Resume Next
If AsyncProp.BytesMax <> 0 Then
RaiseEvent DownloadProgress(CLng(AsyncProp.BytesRead), CLng(AsyncProp.BytesMax), AsyncProp.PropertyName)
downStat = True: Timer1.Enabled = True
End If
End Sub
Private Sub UserControl_Resize()
SizeIt
End Sub
Public Sub BeginDownload(url As String, SaveFile As String)
On Error GoTo ErrorBeginDownload
downStat = True
UserControl.AsyncRead url, vbAsyncTypeByteArray, SaveFile, vbAsyncReadForceUpdate
Timer1.Enabled = True
Exit Sub
ErrorBeginDownload:
downStat = False
MsgBox Err & "开始下载数据失败!" _
& vbCrLf & vbCrLf & "错误:" & Err.Description, vbCritical, "错误"
End Sub
Public Sub SizeIt()
On Error GoTo ErrorSizeIt
With UserControl
.Width = ScaleX(32, vbPixels, vbTwips)
.Height = ScaleY(32, vbPixels, vbTwips)
End With
Exit Sub
ErrorSizeIt:
End Sub
这是一个下载的Activex OCX,不用任何控件就可从HTTP上下载文件,(一定要写在VB 的Activex OCX中!), 支持进度条。 但出错后就不能中止异步,或异步执行不知如何中止,望高手指点!!!!!!!!!!!!!!!!!
Event DownloadProgress(CurBytes As Long, MaxBytes As Long, SaveFile As String)
Event DownloadError(SaveFile As String)
Event DownloadComplete(MaxBytes As Long, SaveFile As String)
Public downStat As Boolean
Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
On Error Resume Next
Dim f() As Byte, fn As Long
If AsyncProp.BytesMax <> 0 Then
fn = FreeFile
f = AsyncProp.Value
Open AsyncProp.PropertyName For Binary Access Write As #fn
Put #fn, , f
Close #fn
Else
RaiseEvent DownloadError(AsyncProp.PropertyName)
End If
RaiseEvent DownloadComplete(CLng(AsyncProp.BytesMax), AsyncProp.PropertyName)
downStat = False
End Sub
Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty)
On Error Resume Next
If AsyncProp.BytesMax <> 0 Then
RaiseEvent DownloadProgress(CLng(AsyncProp.BytesRead), CLng(AsyncProp.BytesMax), AsyncProp.PropertyName)
downStat = True: Timer1.Enabled = True
End If
End Sub
Private Sub UserControl_Resize()
SizeIt
End Sub
Public Sub BeginDownload(url As String, SaveFile As String)
On Error GoTo ErrorBeginDownload
downStat = True
UserControl.AsyncRead url, vbAsyncTypeByteArray, SaveFile, vbAsyncReadForceUpdate
Timer1.Enabled = True
Exit Sub
ErrorBeginDownload:
downStat = False
MsgBox Err & "开始下载数据失败!" _
& vbCrLf & vbCrLf & "错误:" & Err.Description, vbCritical, "错误"
End Sub
Public Sub SizeIt()
On Error GoTo ErrorSizeIt
With UserControl
.Width = ScaleX(32, vbPixels, vbTwips)
.Height = ScaleY(32, vbPixels, vbTwips)
End With
Exit Sub
ErrorSizeIt:
End Sub
这是一个下载的Activex OCX,不用任何控件就可从HTTP上下载文件,(一定要写在VB 的Activex OCX中!), 支持进度条。 但出错后就不能中止异步,或异步执行不知如何中止,望高手指点!!!!!!!!!!!!!!!!!
...全文
相关推荐
VB6Get和POST请求异步处理请求
异步处理主球,能有效地解决xmlhttp组件卡死问题
vb6用的xmlhttp模块,get和post方式提交数据,异步获取,不卡死,十分好用
以前写的一个xmlhttp提交数据的类模块,能有效地解决xmlhttp组件卡死问题,可用于,制件网络投票程序,网络信息收集程序
异步处理-VB6 / VB.NET的基础知识和演练-I
异步过程的基础知识以及VB6和.NET的操作方法
一个基于VB.net的异步Socket网络TCP通信
一个基于VB.net的异步Socket网络TCP通信
一个VB6.0适用的异步消息发送接收处理模块.rar
一个应用程序级的VB6.0消息处理模块,By 飞雪紫翼。此模块可以实现在整个应用程序中的异步消息传送,开发这个模块的本意是为了方便查看程序的调试信息,但做着做着就把它做成了现在这样,自认为功能还算完善,而且可扩展性比较好。还有一点要说明的,在本模块中只对窗体发送消息,如果需要的话可以加上对应用程序中各个类的消息发送。 TODO:在主模块的消息类型枚举定义中添加新的消息类型后应在此处添加相应的中文说明,以便本函数能正确地,处理消息类型说明。 VB消息发送窗口主要演示如何发送自定义消息,并同时演示如何截获类型为MsgTypeFileOption的系统消息。 VB消息接收窗口主要接收[MsgTypeNetWork]类型的消息,并在收到此类消息时显示一个MsgBox。


网络编程
