用vb怎样进行多线程编程

GMMapView 2003-05-09 12:26:48
我试着写了段代码,调试完成退出,生成EXE执行都出现,“该内存不能为只读”的提示!
请帮帮忙看看,谢了:)!
代码:
1、窗体Form1,放置Command1,Text1
Option Explicit
Dim threadone As Long
Dim threadtwo As Long

Private Sub Command1_Click()
Dim threadidone As Long
Dim threadidtwo As Long
vbbl = True
threadone = CreateThread(0, 0, AddressOf Module1.copyF, 0, 0, threadidone)
threadtwo = CreateThread(0, 0, AddressOf Module1.TestData, 0, 0, threadidtwo)
End Sub

Private Sub Form_Unload(Cancel As Integer)
' CloseHandle threadone
' CloseHandle threadtwo
End Sub
2、标准模块 Module1
Declare Function CreateThread Lib "kernel32" (ByVal lpSecurityAttributes As Long, _
ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, _
ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, _
lpThreadId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public vbbl As Boolean

Public Sub TestData()
While vbbl
Form1.Text1.Text = Rnd(10) * 100
Wend
If Not vbbl Then
Exit Sub
End If
End Sub

Public Sub copyF()
FileCopy "C:\Documents and Settings\pys1\桌面\kkk.mdb", "C:\Documents and Settings\pys1\桌面\新建文件夹\PPP.mdb"
vbbl = False
End Sub
...全文
23 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
followme003 2003-05-09
为什么我调试的时候关掉窗口vb也跟着退出了?
回复
James0001 2003-05-09
线程函数的格式不对!!!
标准的线程函数的格式是:

VB: Function ThreadFunc(ByVal lParam As Long) As Long
'C: DWORD WINAPI ThreadFunc( LPVOID );

其中ThreadFunc是一个自定义的函数名字,如:
Function TestData(ByVal lParam As Long) As Long
'...
End Function
回复
pipipig 2003-05-09
应该也没有问题啊 不明白乐
回复
pipipig 2003-05-09
还是看不出 可能是vbbl = False有问题
回复
GMMapView 2003-05-09
pipipig() 文件没问题
回复
pipipig 2003-05-09
看了半天看不出

可能是copyF()中文件没找到吧?加一条
On Error Resume Next

关闭的时候肯定有问题,去掉纳2个注释
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7490

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-09 12:26
社区公告
暂无公告