📄 frmmultithread.frm
字号:
VERSION 5.00
Begin VB.Form frmMultiThread
Caption = "VBThread Demo"
ClientHeight = 4245
ClientLeft = 60
ClientTop = 345
ClientWidth = 6990
LinkTopic = "Form1"
ScaleHeight = 4245
ScaleWidth = 6990
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox txtParam
Height = 315
Index = 2
Left = 2640
Locked = -1 'True
TabIndex = 29
Text = "0"
Top = 1440
Width = 615
End
Begin VB.TextBox txtParam
Height = 315
Index = 1
Left = 2640
Locked = -1 'True
TabIndex = 28
Text = "0"
Top = 1020
Width = 615
End
Begin VB.TextBox txtParam
Height = 315
Index = 0
Left = 2640
Locked = -1 'True
TabIndex = 27
Text = "0"
Top = 600
Width = 615
End
Begin VB.TextBox txtStarted
Height = 315
Index = 2
Left = 4200
Locked = -1 'True
TabIndex = 22
Text = "False"
Top = 1440
Width = 615
End
Begin VB.TextBox txtStarted
Height = 315
Index = 1
Left = 4200
Locked = -1 'True
TabIndex = 21
Text = "False"
Top = 1020
Width = 615
End
Begin VB.TextBox txtStarted
Height = 315
Index = 0
Left = 4200
Locked = -1 'True
TabIndex = 20
Text = "False"
Top = 600
Width = 615
End
Begin VB.TextBox txtLoaded
Height = 315
Index = 2
Left = 3420
Locked = -1 'True
TabIndex = 19
Text = "False"
Top = 1440
Width = 615
End
Begin VB.TextBox txtLoaded
Height = 315
Index = 1
Left = 3420
Locked = -1 'True
TabIndex = 18
Text = "False"
Top = 1020
Width = 615
End
Begin VB.TextBox txtLoaded
Height = 315
Index = 0
Left = 3420
Locked = -1 'True
TabIndex = 17
Text = "False"
Top = 600
Width = 615
End
Begin VB.ComboBox cboPriority2
Enabled = 0 'False
Height = 315
ItemData = "frmMultiThread.frx":0000
Left = 4980
List = "frmMultiThread.frx":001E
Style = 2 'Dropdown List
TabIndex = 10
Top = 1440
Width = 1695
End
Begin VB.ComboBox cboPriority1
Enabled = 0 'False
Height = 315
ItemData = "frmMultiThread.frx":0069
Left = 4980
List = "frmMultiThread.frx":0087
Style = 2 'Dropdown List
TabIndex = 9
Top = 1020
Width = 1695
End
Begin VB.ComboBox cboPriority0
Enabled = 0 'False
Height = 315
ItemData = "frmMultiThread.frx":00D2
Left = 4980
List = "frmMultiThread.frx":00F0
Style = 2 'Dropdown List
TabIndex = 8
Top = 600
Width = 1695
End
Begin VB.TextBox txtText
Height = 315
Index = 2
Left = 1275
Locked = -1 'True
TabIndex = 7
Text = "0"
Top = 1440
Width = 1215
End
Begin VB.TextBox txtText
Height = 315
Index = 1
Left = 1275
Locked = -1 'True
TabIndex = 6
Text = "0"
Top = 1020
Width = 1215
End
Begin VB.TextBox txtText
Height = 315
Index = 0
Left = 1275
Locked = -1 'True
TabIndex = 5
Text = "0"
Top = 600
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Show Thread Status"
Enabled = 0 'False
Height = 375
Left = 2520
TabIndex = 4
Top = 3720
Width = 1995
End
Begin VB.CommandButton Command5
Caption = "Pause"
Enabled = 0 'False
Height = 375
Left = 3525
TabIndex = 3
Top = 3240
Width = 975
End
Begin VB.CommandButton Command4
Caption = "Start"
Enabled = 0 'False
Height = 375
Left = 2505
TabIndex = 2
Top = 3240
Width = 975
End
Begin VB.CommandButton Command3
Caption = "Load"
Height = 375
Left = 1478
TabIndex = 1
Top = 3240
Width = 975
End
Begin VB.CommandButton Command2
Caption = "Unload"
Enabled = 0 'False
Height = 375
Left = 4538
TabIndex = 0
Top = 3240
Width = 975
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Param"
Height = 195
Index = 3
Left = 2640
TabIndex = 30
Top = 240
Width = 450
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "Status are monitored with Thread's events !!!"
Height = 195
Left = 1890
TabIndex = 26
Top = 2400
Width = 3150
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "Refer to the code to see how it was implemented with VBThread."
Height = 195
Left = 1200
TabIndex = 25
Top = 2700
Width = 4590
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Started"
Height = 195
Index = 2
Left = 4200
TabIndex = 24
Top = 240
Width = 510
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Loaded"
Height = 195
Index = 1
Left = 3420
TabIndex = 23
Top = 240
Width = 540
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "All of the loops is done in its own thread, without 'DoEvents' or another interupt ."
Height = 195
Left = 683
TabIndex = 16
Top = 2100
Width = 5625
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Loop"
Height = 195
Index = 0
Left = 1275
TabIndex = 15
Top = 240
Width = 360
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Priority"
Height = 195
Left = 4980
TabIndex = 14
Top = 240
Width = 465
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Function 3"
Height = 195
Index = 2
Left = 315
TabIndex = 13
Top = 1500
Width = 750
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Function 2"
Height = 195
Index = 1
Left = 315
TabIndex = 12
Top = 1080
Width = 750
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Function 1"
Height = 195
Index = 0
Left = 315
TabIndex = 11
Top = 660
Width = 750
End
End
Attribute VB_Name = "frmMultiThread"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim WithEvents myThread0 As ThreadVB
Attribute myThread0.VB_VarHelpID = -1
Dim WithEvents myThread1 As ThreadVB
Attribute myThread1.VB_VarHelpID = -1
Dim WithEvents myThread2 As ThreadVB
Attribute myThread2.VB_VarHelpID = -1
Private Sub cboPriority0_Click()
On Error Resume Next
myThread0.fnPriority = cboPriority0.ItemData(cboPriority0.ListIndex)
End Sub
Private Sub cboPriority1_Click()
On Error Resume Next
myThread1.fnPriority = cboPriority1.ItemData(cboPriority1.ListIndex)
End Sub
Private Sub cboPriority2_Click()
On Error Resume Next
myThread2.fnPriority = cboPriority2.ItemData(cboPriority2.ListIndex)
End Sub
Private Sub Command1_Click()
Dim strValue As String
strValue = "FunctionNo;fnAddress;fnParam;fnLoaded;fnStarted;hdlThread;Tag;ThreadID;Priority" & vbCrLf
strValue = strValue & "1" & ";" & myThread0.fnAddress & ";" & myThread0.fnParam & ";" & myThread0.fnLoaded & ";" & myThread0.fnStarted & ";" & myThread0.hdlThread & ";" & myThread0.Tag & ";" & myThread0.ThreadID & ";" & myThread0.fnPriority & vbCrLf
strValue = strValue & "2" & ";" & myThread1.fnAddress & ";" & myThread1.fnParam & ";" & myThread1.fnLoaded & ";" & myThread1.fnStarted & ";" & myThread1.hdlThread & ";" & myThread1.Tag & ";" & myThread1.ThreadID & ";" & myThread1.fnPriority & vbCrLf
strValue = strValue & "3" & ";" & myThread2.fnAddress & ";" & myThread2.fnParam & ";" & myThread2.fnLoaded & ";" & myThread2.fnStarted & ";" & myThread2.hdlThread & ";" & myThread2.Tag & ";" & myThread2.ThreadID & ";" & myThread2.fnPriority & vbCrLf
MsgBox strValue, vbOKOnly + vbInformation, "Thread Info"
End Sub
Private Sub Command2_Click()
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = False
cboPriority0.Enabled = False
cboPriority1.Enabled = False
cboPriority2.Enabled = False
cboPriority0.ListIndex = 3
cboPriority1.ListIndex = 3
cboPriority2.ListIndex = 3
myThread0.UnloadFunction
myThread1.UnloadFunction
myThread2.UnloadFunction
Set myThread0 = Nothing
Set myThread1 = Nothing
Set myThread2 = Nothing
End Sub
Private Sub Command3_Click()
Set myThread0 = New ThreadVB
Set myThread1 = New ThreadVB
Set myThread2 = New ThreadVB
Command3.Enabled = False
Command1.Enabled = True
Command2.Enabled = True
Command4.Enabled = True
cboPriority0.Enabled = True
cboPriority1.Enabled = True
cboPriority2.Enabled = True
myThread0.LoadFunction AddressOf modMultiThread.DoSomething0
myThread1.LoadFunction AddressOf modMultiThread.DoSomething1, 200&
myThread2.LoadFunction AddressOf modMultiThread.DoSomething2, 300&
End Sub
Private Sub Command4_Click()
Command4.Enabled = False
Command5.Enabled = True
myThread0.StartFunction
myThread1.StartFunction
myThread2.StartFunction
End Sub
Private Sub Command5_Click()
Command5.Enabled = False
Command4.Enabled = True
myThread0.PauseFunction
myThread1.PauseFunction
myThread2.PauseFunction
End Sub
Public Sub DoSomething0(ByVal lParam As Long)
Static i As Double
txtParam(0).Text = lParam
Do
txtText(0).Text = i
txtText(0).Refresh
i = i + 1
Loop
Form1.Show
End Sub
Public Sub DoSomething1(ByVal lParam As Long)
Static i As Double
txtParam(1).Text = lParam
Do
txtText(1).Text = i
txtText(1).Refresh
i = i + 1
Loop
End Sub
Public Sub DoSomething2(ByVal lParam As Long)
Static i As Double
txtParam(2).Text = lParam
Do
txtText(2).Text = i
txtText(2).Refresh
i = i + 1
Loop
End Sub
Private Sub Form_Load()
cboPriority0.ListIndex = 3
cboPriority1.ListIndex = 3
cboPriority2.ListIndex = 3
End Sub
Private Sub myThread0_FunctionLoaded(lpThreadID As Long)
txtLoaded(0).Text = "True"
End Sub
Private Sub myThread0_FunctionPaused(dwPausedCount As Long)
txtStarted(0).Text = "False"
End Sub
Private Sub myThread0_FunctionStarted(dwPausedCount As Long)
txtStarted(0).Text = "True"
End Sub
Private Sub myThread0_FunctionUnloaded(dwExitStatus As Long)
txtStarted(0).Text = "False"
txtLoaded(0).Text = "False"
End Sub
Private Sub myThread1_FunctionLoaded(lpThreadID As Long)
txtLoaded(1).Text = "True"
End Sub
Private Sub myThread1_FunctionPaused(dwPausedCount As Long)
txtStarted(1).Text = "False"
End Sub
Private Sub myThread1_FunctionStarted(dwPausedCount As Long)
txtStarted(1).Text = "True"
End Sub
Private Sub myThread1_FunctionUnloaded(dwExitStatus As Long)
txtStarted(1).Text = "False"
txtLoaded(1).Text = "False"
End Sub
Private Sub myThread2_FunctionLoaded(lpThreadID As Long)
txtLoaded(2).Text = "True"
End Sub
Private Sub myThread2_FunctionPaused(dwPausedCount As Long)
txtStarted(2).Text = "False"
End Sub
Private Sub myThread2_FunctionStarted(dwPausedCount As Long)
txtStarted(2).Text = "True"
End Sub
Private Sub myThread2_FunctionUnloaded(dwExitStatus As Long)
txtStarted(2).Text = "False"
txtLoaded(2).Text = "False"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -