In fact, using Visual Basic ActiveX exe technology can easily implement multithreading.
Let's not talk about the principle. Let's give an example. If you are interested, you can discuss it together.
1. Create a new project, select ActiveX Exe as the type, and rename the project to TestExe.
Add a Form in the project and put a Timer control.
Rename Class1 to clsTest. Note that its Instancing must be set to 5-MultiUse. The following code is used:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private WithEvents oTimer As Timer
Private frmTmp As Form1
Private lTotalLoop As Long
Private bDoStop As Boolean
Private lInterval As Long
Public Event Progress (ByVal lProgress As Long)
Public Sub StartSub (ByVal lTotal As Long)
LTotalLoop = lTotal
OTimer. Enabled = True
End Sub
Public Sub StopSub ()
BDoStop = True
End Sub
Private Sub Class_Initialize ()
Set frmTmp = New Form1
Load frmTmp
Set oTimer = frmTmp. Timer1
OTimer. Enabled = False
BDoStop = False
LInterval = 1
End Sub
Private Sub DoLoop ()
Dim I As Long
For I = 0 To lTotalLoop
Sleep (lInterval)
RaiseEvent Progress (I)
If bDoStop = True Then
Exit Sub