CloseHandle hThread End SubPrivate Sub Form_Unload(Cancel As Integer) If hThread <> 0 Then TerminateThread hThread, 0& End Sub'In a module Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public hThread As Long, hThreadID As LongPublic Sub AsyncThread() 'Let this thread sleep for 10 seconds Sleep 10000 hThread = 0 End Sub你在VB6中试试这段代码!就知道可不可以了。
VB5可以实现另外我用VB6加动态库的方法也实现了多线程
to wx_zzm() : 请赐教! put it here or send me the code to [email protected].
想要的话email to :[email protected]
只要参数传递正确,生成的EXE程序是没有问题的。
在IDE环境中,不能使用VB的停止按纽来非法关闭程序(切记!!!)
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
CloseHandle hThread
End SubPrivate Sub Form_Unload(Cancel As Integer)
If hThread <> 0 Then TerminateThread hThread, 0&
End Sub'In a module
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public hThread As Long, hThreadID As LongPublic Sub AsyncThread()
'Let this thread sleep for 10 seconds
Sleep 10000
hThread = 0
End Sub你在VB6中试试这段代码!就知道可不可以了。
请赐教! put it here or send me the code to [email protected].
[email protected]