使用Visual Basic 6實現真正實用的多執行緒

來源:互聯網
上載者:User
 
事實上使用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.