我想在后台执行一个时间很长的循环,不影响前台与用户的交互,能有什么方法吗(除了CreateThread)?

解决方案 »

  1.   

    我有一个多线程的类,在VB6+WIN98中使用正常。
    想要的话email to :[email protected]
      

  2.   

    如果循环时间较长,可在循环体内加上DoEvents语句来让程序执行其他操作而不影响。
      

  3.   

    在VB中使用CreateThread是没有问题的,关键是参数,
    只要参数传递正确,生成的EXE程序是没有问题的。
    在IDE环境中,不能使用VB的停止按纽来非法关闭程序(切记!!!)
      

  4.   

    我的循环理由一个通讯过程,一次就得很长时间,这个用doevent也没有什么作用吧
      

  5.   

    Private Sub Command1_Click()
        hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
        
        CloseHandle hThread
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        If hThread <> 0 Then TerminateThread hThread, 0&
    End Sub'In a module
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    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 TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Public hThread As Long, hThreadID As LongPublic Sub AsyncThread()
        'Let this thread sleep for 10 seconds
        Sleep 10000
        hThread = 0
    End Sub你在VB6中试试这段代码!就知道可不可以了。
      

  6.   

    VB5可以实现另外我用VB6加动态库的方法也实现了多线程
      

  7.   

    to wx_zzm() :
        请赐教! put it here or send me the code to [email protected].
      

  8.   

    也想学习一下。:)
    [email protected]
      

  9.   

    是我错了,CreateThread 能在vb中运行,但不很安全,给分了。