{"id":124,"date":"2006-05-10T21:19:25","date_gmt":"2006-05-10T13:19:25","guid":{"rendered":"http:\/\/tmp.xujiwei.com\/blog\/?p=124"},"modified":"2010-01-29T12:56:00","modified_gmt":"2010-01-29T04:56:00","slug":"vb-multithread-class","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2006\/05\/vb-multithread-class\/","title":{"rendered":"[VB] \u4e00\u4e2a\u64cd\u4f5c\u591a\u7ebf\u7a0b\u7684\u7c7b"},"content":{"rendered":"<p>\u6839\u636e\u70b9\u775b\u5de5\u4f5c\u5ba4\u7684\u591a\u7ebf\u7a0b\u7c7b\u6539\u5199\u7684\uff0c\u4e0d\u8fc7\u6ca1\u6709\u7ecf\u8fc7\u4e25\u683c\u6d4b\u8bd5\uff0c\u597d\u50cf\u5de5\u4f5c\u4e0d\u662f\u5f88\u7a33\u5b9a\uff0c\u5982\u679c\u4f7f\u7528\u4e0d\u5f53\u4f1a\u51fa\u9519\u7684\u8bf4\u3002<\/p>\n<blockquote>\n<div id=\"_mcePaste\">\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Option Explicit<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Type SECURITY_ATTRIBUTES<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> nLength As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> lpSecurityDescriptor As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> bInheritHandle As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Type<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function CreateThread Lib \"kernel32\" (lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function CreateThreadL Lib \"kernel32\" Alias \"CreateThread\" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function TerminateThread Lib \"kernel32\" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function SetThreadPriority Lib \"kernel32\" (ByVal hThread As Long, ByVal nPriority As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function GetThreadPriority Lib \"kernel32\" (ByVal hThread As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function ResumeThread Lib \"kernel32\" (ByVal hThread As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function SuspendThread Lib \"kernel32\" (ByVal hThread As Long) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function GetCurrentThread Lib \"kernel32\" () As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function GetCurrentThreadId Lib \"kernel32\" () As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Sub ExitThread Lib \"kernel32\" (Optional ByVal dwExitCode As Long = 0)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Declare Function GetLastError Lib \"kernel32\" () As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">' \u5e38\u6570\u5e38\u91cf<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const MAXLONG = &amp;H7FFFFFFF<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">' \u7ebf\u7a0b\u4f18\u5148\u7ea7\u5e38\u91cf<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_BASE_PRIORITY_IDLE = -15<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_BASE_PRIORITY_LOWRT = 15<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_BASE_PRIORITY_MAX = 2<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_BASE_PRIORITY_MIN = -2<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_NORMAL = 0<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const THREAD_PRIORITY_ERROR_RETURN = (MAXLONG)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">' \u7ebf\u7a0b\u521b\u5efa\u6807\u5fd7<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_ALWAYS = 2<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_NEW = 1<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_NEW_CONSOLE = &amp;H10<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_NEW_PROCESS_GROUP = &amp;H200<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_NO_WINDOW = &amp;H8000000<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_PROCESS_DEBUG_EVENT = 3<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_SUSPENDED = &amp;H4<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Const CREATE_THREAD_DEBUG_EVENT = 2<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">' \u7ebf\u7a0b\u4f18\u5148\u7ea7\u7ed3\u6784<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Enum ThreadPriority<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Lowest = THREAD_PRIORITY_LOWEST<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> BelowNormal = THREAD_PRIORITY_BELOW_NORMAL<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Normal = THREAD_PRIORITY_NORMAL<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> AboveNormal = THREAD_PRIORITY_ABOVE_NORMAL<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Highest = THREAD_PRIORITY_HIGHEST<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Enum<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private mAttrib As SECURITY_ATTRIBUTES<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private mEnabled As Boolean<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private mThreadHandle As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private mThreadID As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private mTerminate As Boolean<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Property Get ThreadID() As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> ThreadID = mThreadID<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Property<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Property Get ThreadHandle() As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> ThreadHandle = mThreadHandle<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Property<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Function Create(ByVal cFunction As Long, Optional ByVal cPriority As ThreadPriority, Optional ByVal cEnabled As Boolean = True) As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Dim CreateFlag As Long<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mThreadHandle &lt;&gt; 0 Then TerminateMe<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mEnabled = cEnabled<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mEnabled Then<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> CreateFlag = CREATE_NEW<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Else<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> CreateFlag = CREATE_SUSPENDED<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> End If<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mAttrib.nLength = Len(mAttrib)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mThreadHandle = CreateThreadL(0, 0, cFunction, 0&amp;, CreateFlag, mThreadID)<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mThreadHandle = 0 Then<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> MsgBox \"Create thread failed!Error code:\" &amp; GetLastError, vbOKOnly Or vbCritical, \"Error\"<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> End If<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Function<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Sub SuspendMe()<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mThreadHandle = 0 Or mEnabled = False Then Exit Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If SuspendThread(mThreadHandle) &lt;&gt; -1 Then<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mEnabled = False<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Else<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> MsgBox \"Suspend thread failed!Error code:\" &amp; GetLastError, vbOKOnly Or vbCritical, \"Error\"<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> End If<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Sub ResumeMe()<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mThreadHandle = 0 Or mEnabled = True Then Exit Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If ResumeThread(mThreadHandle) &lt;&gt; -1 Then<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mEnabled = True<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> Else<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> MsgBox \"Resume thread failed!Error code:\" &amp; GetLastError, vbOKOnly Or vbCritical, \"Error\"<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> End If<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Public Sub TerminateMe()<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> If mThreadHandle = 0 Then Exit Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> TerminateThread mThreadHandle, 0<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> mThreadHandle = 0<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> 'mTerminate = True<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> 'Do<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> ' \u00a0 \u00a0DoEvents <\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> 'Loop Until mTerminate<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Sub<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">Private Sub Class_Terminate()<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"> 'TerminateThread mThreadHandle, 0<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\"><br \/>\n<\/span><\/div>\n<div id=\"_mcePaste\"><span style=\"font-style: normal;\">End Sub<\/span><\/div>\n<\/div>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u6839\u636e\u70b9\u775b\u5de5\u4f5c\u5ba4\u7684\u591a\u7ebf\u7a0b\u7c7b\u6539\u5199\u7684\uff0c\u4e0d\u8fc7\u6ca1\u6709\u7ecf\u8fc7\u4e25\u683c\u6d4b\u8bd5\uff0c\u597d\u50cf\u5de5\u4f5c\u4e0d\u662f\u5f88\u7a33\u5b9a\uff0c\u5982\u679c\u4f7f &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2006\/05\/vb-multithread-class\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[83,76],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/124"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}