📄 thread.bas
字号:
Attribute VB_Name = "Thread"
Option Explicit
' Windows (Constant, Data structure, API) declaration
Public Const CREATE_SUSPENDED = &H4
Public Const THREAD_PRIORITY_NORMAL = &H0
Public Const THREAD_PRIORITY_TIME_CRITICAL = &H15
Public Const STILL_ACTIVE = &H103
Global ThreadHandle As Long
Global m_bContinue As Boolean
Global m_bFlag As Boolean 'thread flag
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function GetTickCount Lib "kernel32" () As Long
Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Sub EventThread()
Dim i As Integer
Dim dwStartTime As Long
Dim dwCurrentTime As Long
Dim dwTime As Long
Dim EventCount_IDI(0 To 3) As Long
Dim ratio_IDI(0 To 3) As Single
' Dim szBuf_IDI(0 To 3) As String * 20
Dim usEventType As Long
For i = 0 To 3
EventCount_IDI(i) = 0
Next i
ptCheckEvent.EventType = DRV_GetAddress(usEventType)
ptCheckEvent.Milliseconds = 1000
dwStartTime = GetTickCount()
While (m_bContinue)
m_bFlag = 1
If (DRV_CheckEvent(m_DriverHandle, ptCheckEvent) = SUCCESS) Then
If (usEventType = ADS_EVT_INTERRUPT_IDI0) Then
EventCount_IDI(0) = EventCount_IDI(0) + 1
End If
If (usEventType = ADS_EVT_INTERRUPT_IDI1) Then
EventCount_IDI(1) = EventCount_IDI(1) + 1
End If
If (usEventType = ADS_EVT_INTERRUPT_DI0) Then
EventCount_IDI(2) = EventCount_IDI(2) + 1
End If
If (usEventType = ADS_EVT_INTERRUPT_DI1) Then
EventCount_IDI(3) = EventCount_IDI(3) + 1
End If
End If
dwCurrentTime = GetTickCount()
dwTime = dwCurrentTime - dwStartTime
If (dwTime >= 1000) Then
For i = 0 To 3
ratio_IDI(i) = CSng((CLng(EventCount_IDI(i)) / CSng(dwTime) * 1000#))
EventCount_IDI(i) = 0
Next i
Form1.editIntCount_IDI0.Text = ratio_IDI(0)
Form1.editIntCount_IDI1.Text = ratio_IDI(1)
Form1.editIntCount_DI0.Text = ratio_IDI(2)
Form1.editIntCount_DI1.Text = ratio_IDI(3)
dwStartTime = GetTickCount()
End If
Wend
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -