我照着下面的例子做的多线程,可是每次调试一关闭,vb也跟着关闭了,请问怎么解决

followme003 2003-05-09 05:09:58
使用API函数CreateThread,但是VB6不是最好的多线程支持,建议使用VC等工具更为简便.
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
调用:
hnd = CreateThread(0, 2000, AddressOf线程体名(函数名) ,参数 , 0, threadid)

实例代码:
Dim lnull As Long
Dim threadidone As Long
Dim threadidtwo As Long
Dim threadhwndone As Long
Dim threadhwndtwo As Long
lnull = 0
vbbl = True
threadhwndone = CreateThread(lnull, 0, AddressOf Module1.one, _
lnull, 0, threadidone)
threadhwndtwo = CreateThread(lnull, 0, AddressOf Module1.two, _
lnull, 0, threadidtwo)
If threadhwndone = 0 Or threadhwndtwo = 0 Then MsgBox "can't _
create thread" 4.command2中代码是:
form3.show
5.再向工程中添加一标准模块。代码如下:
Public Declare Function CreateThread Lib "kernel32" _
(lpThreadAttributes As Long, ByVal dwStackSize As Long, _
lpStartAddress As Long, lpParameter As Any, ByVal _
dwCreationFlags As Long, lpThreadId As Long) As Long
Public vbbl As Boolean
Public Sub one()
Dim j As Integer
While vbbl = True
While j < 10
form1.Text1.BackColor = vbBlue
j = j + 1
Wend
j = 1
form1.Text1.BackColor = vbRed
Wend
End Sub
Public Sub two()
Dim j As Integer
form2.Show
While vbbl = True
form2.Text1 = Rnd(10) * 100
Wend
End Sub
...全文
14 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
followme002 2003-06-02
是啊,呵呵
回复
sworddx 2003-06-01
要在VB里面跨线程,决不要在设计环境下调试运行。编译出来再说。
回复
baixiao2222 2003-06-01
你把程序编译出来,然后运行做为测试。
回复
rfc2459 2003-06-01
up
回复
followme002 2003-06-01
哦哦
回复
xmxjh 2003-05-09
最好不要在VB6中用多线程,在任何时间都有可能出错!没有理由……
回复
of123 2003-05-09
线程不能跟踪调试!
回复
http://expert.csdn.net/Expert/topic/1595/1595902.xml?temp=.2075312

希望对你有所小小帮助!
回复
叶帆 2003-05-09
在VB中最好别用线程,除非你的程序没有一点错误,否则...
回复
发帖
VB基础类
创建于2007-09-28

7493

社区成员

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