CreateThread可以,
不过在VB中最好不要用。如果可以,考虑用Timer试试

解决方案 »

  1.   

    在DLL运行期间,Timer事件不会触发啊!
      

  2.   

    忘了,好像用CreateThread创建的线程里使用的语句,只能是自己写的代码
      

  3.   

    忘了,好像用CreateThread创建的线程里使用的语句,只能是自己写的代码
      

  4.   

    CreateThread在VB6中是否不能正常运行?
    我的代码如下:模块:
    'Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
    Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongSub main()
    Load Form1
    Form1.Show
    End Sub
    Public Sub c1()
    '.......
        LTDelay 2
        MsgBox "OK1"
    End SubPublic Sub c2()
    '......
        LTDelay 2
        MsgBox "OK2"
    End SubPublic Function LTDelay(ByVal lSec As Long) As Long
        Dim lNow As Date
        LTDelay = 0
        lNow = Now
        Do While (DateDiff("s", lNow, Now) < lSec)
            'DoEvents
        Loop
    End Function
    窗体:
    Private hthread1 As Long
    Private hthread2 As Long
    Private ithread1 As Long
    Private ithread2 As LongPrivate Sub Command1_Click()ithread1 = CreateThread(ByVal 0&, ByVal 2000&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1) '- -&acute;&acute;&frac12;¨&Iuml;&szlig;&sup3;&Igrave;&Ograve;&raquo;
    ithread2 = CreateThread(ByVal 0&, ByVal 2000&, AddressOf c2, ByVal 0&, ByVal 0&, hthread1) '- -&acute;&acute;&frac12;¨&Iuml;&szlig;&sup3;&Igrave;&para;&thorn;
    LTDelay 10
    CloseHandle ithread1 '- -&sup1;&Oslash;±&Otilde;&Iuml;&szlig;&sup3;&Igrave;&Ograve;&raquo;
    CloseHandle ithread2 '- -&sup1;&Oslash;±&Otilde;&Iuml;&szlig;&sup3;&Igrave;&para;&thorn;End Sub
    跟踪的结果是,根本没运行。用过的朋友,能给个提示否?
      

  5.   

    Option ExplicitPublic Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
    Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As LongPublic id As LongPublic Function AddText()
        Do
            Form1.Text1.Text = "Adding to Text1 - "
            doevents
        Loop
    End FunctionOption ExplicitPrivate Sub Command1_Click()
        id = CreateThread(ByVal 0&, ByVal 0&, AddressOf AddText, ByVal 0&, 0, id)
    End SubPrivate Sub Command2_Click()
        Call TerminateThread(id, ByVal 0&)
    End Sub
      

  6.   

    问题已解决
    代码如下模块中:(AddressOf 的过程不能再调用程序中其它部分!!!)
    'Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
    Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPublic Sub Main()
    Load Form1
    Form1.Show
    End Sub
    Public Sub c1()
    '.......
        Close #1
        Open App.Path + "\Error.txt" For Append As #1
        Print #1, CStr(Now) + ":"; "OK1 BEGIN"
        Close #1
        
        Dim lNow As Date
        lNow = Now
        Do While (DateDiff("s", lNow, Now) < 6)
            'DoEvents
        Loop
        
        Close #1
        Open App.Path + "\Error.txt" For Append As #1
        Print #1, CStr(Now) + ":"; "OK1 END"
        Close #1
    End SubPublic Sub c2()
    '......
        Close #1
        Open App.Path + "\Error.txt" For Append As #1
        Print #1, CStr(Now) + ":"; "OK2 BEGIN"
        Close #1
        
        Dim lNow As Date
        lNow = Now
        Do While (DateDiff("s", lNow, Now) < 6)
            'DoEvents
        Loop
        
        Close #1
        Open App.Path + "\Error.txt" For Append As #1
        Print #1, CStr(Now) + ":"; "OK2 END"
        Close #1
    End SubPublic Function LTDelay(ByVal lSec As Long) As Long
        Dim lNow As Date
        LTDelay = 0
        lNow = Now
        Do While (DateDiff("s", lNow, Now) < lSec)
            'DoEvents
        Loop
    End Function
    Public Function WriteLog(lData As String)
    On Error GoTo Exec_Error
        Close #1
        Open App.Path + "\Error.txt" For Append As #1
        Print #1, CStr(Now) + ":"; lData
        Close #1
        Exit Function
    Exec_Error:
        MsgBox "&ETH;&acute;&Egrave;&Otilde;&Ouml;&frac34;&Icirc;&Auml;&frac14;&thorn;&sup3;&ouml;&acute;í:" + Err.Description, vbCritical + vbOKOnly, "&sup3;&ouml;&acute;í!"
    End Function
    窗体中:
    Private hthread1 As Long
    Private hthread2 As Long
    Private ithread1 As Long
    Private ithread2 As LongPrivate Sub Command1_Click()
    Dim lRet As Longithread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1) '- -&acute;&acute;&frac12;¨&Iuml;&szlig;&sup3;&Igrave;&Ograve;&raquo;
    LTDelay 4
    ithread2 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c2, ByVal 0&, ByVal 0&, hthread1) '- -&acute;&acute;&frac12;¨&Iuml;&szlig;&sup3;&Igrave;&para;&thorn;WriteLog "Delay 10 BEGIN"
    LTDelay 20
    WriteLog "Delay 10 END"CloseHandle ithread1 '- -&sup1;&Oslash;±&Otilde;&Iuml;&szlig;&sup3;&Igrave;&Ograve;&raquo;
    CloseHandle ithread2 '- -&sup1;&Oslash;±&Otilde;&Iuml;&szlig;&sup3;&Igrave;&para;&thorn;End Sub