用vb怎样进行多线程编程
我试着写了段代码,调试完成退出,生成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