Use Visual Basic 6 to implement real and practical multi-thread processing

Source: Internet
Author: User


In fact, using Visual Basic ActiveX exe technology can easily implement multithreading.
Let's not talk about the principle. Let's give an example. If you are interested, you can discuss it together.
1. Create a new project, select ActiveX Exe as the type, and rename the project to TestExe.
Add a Form in the project and put a Timer control.
Rename Class1 to clsTest. Note that its Instancing must be set to 5-MultiUse. The following code is used:
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.