一聚教程网:一个值得你收藏的教程网站

热门教程

使用Visual Basic 6实现真正实用的多线程处理

时间:2022-07-02 11:14:53 编辑:袖梨 来源:一聚教程网

 
事实上使用Visual Basic的ActiveX exe技术可以轻松的实现多线程处理.
原理先不说了,先举个示例,有兴趣的话大家可以一起讨论
1.新建一个工程,类型选择ActiveX Exe,工程重命名为TestExe
在工程中添加一个Form,放上一个Timer控件.
将Class1改名为clsTest,注意其Instancing要设置为5-MultiUse, 以下是其代码:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private WithEvents oTimer As Timer
Private frmTmp As Form1
Private lTotalLoop As Long
Private bDoStop As Boolean
Private lInterval As Long
Public Event Progress(ByVal lProgress As Long)
Public Sub StartSub(ByVal lTotal As Long)
      lTotalLoop = lTotal
      oTimer.Enabled = True
End Sub
Public Sub StopSub()
      bDoStop = True
End Sub
Private Sub Class_Initialize()
      Set frmTmp = New Form1
      Load frmTmp
      Set oTimer = frmTmp.Timer1
      oTimer.Enabled = False
      bDoStop = False
      lInterval = 1
End Sub
Private Sub DoLoop()
      Dim i As Long
      For i = 0 To lTotalLoop
     Sleep (lInterval)
     RaiseEvent Progress(i)
    
     If bDoStop = True Then
         Exit Sub

热门栏目