864
社区成员




Private Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, _
ByVal dwStackSize As Long, _
ByVal lpStartAddress As Long, _
ByVal lpParameter As Long, _
ByVal dwCreationFlags As Long, _
lpThreadId As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim SendThreadID As Long
Dim ClassAddress As Long
IsRun = 1
CopyMemory ClassAddress, Me, 4
Call CreateThread(Null, ByVal 0&, AddressOf Module1.NewThread, ClassAddress, ByVal 0&, SendThreadID)
End Sub
Private Sub Command2_Click()
IsRun = 0
End Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public IsRun As Long
Public Function NewThread(ByVal pParam As Long) As Long
Dim lSaveTime As Long
Dim lNowTime As Long
Dim FormObj As Form1
Dim i As Long
Dim ClassAddress As Long
Dim MCount As Long
Dim SCount As Long
lSaveTime = GetTickCount
MCount = 0
i = 0
ClassAddress = 0
CopyMemory FormObj, pParam, 4
Do
Sleep 3
lNowTime = GetTickCount
SCount = lNowTime - lSaveTime
If SCount > 1000 Then
lSaveTime = lNowTime
i = i + 1
FormObj.Label1.Caption = i & " 秒(线程运行时间)"
End If
Loop While IsRun = 1
CopyMemory FormObj, ClassAddress, 4
End Function