Solved

How to run multiple threads in VB???

Posted on 2003-11-17
7
1,066 Views
Last Modified: 2011-09-20
I want to run 5 subroutines at the same time. (in parallel)
any ideas on how to do this with VB6??

Thanks
0
Comment
Question by:davemiles
7 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 9766132
You can create ActiveX EXEs and call them.  They each would have their own timer.  Then you would start all 6.  If you need to know information back from them then give them events to talk back with your main app.
0
 

Author Comment

by:davemiles
ID: 9767015
ActiveX exe could work...
but i need to be able to use the mscomm control.

how can i use the control from the activex exe?

0
 
LVL 15

Accepted Solution

by:
SRigney earned 250 total points
ID: 9767310
An ActiveX EXE is just like using a regular EXE.  You can add a form to your ActiveX EXE and use it there.  You can keep the form hidden so it doesn't create desktop clutter.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 48

Expert Comment

by:Mikal613
ID: 9768616
you could (even though vb6 doesnt support it) but i would use Semaphores and Mutex's to tame your processes.
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9770273
"how can i use the control from the activex exe?"

take a form dont call the forms show method just keep it loaded and u can use the control.
you can load a form without making it visible using the load method
0
 
LVL 1

Expert Comment

by:RocketMan801
ID: 9771579
multi-threading under vb 6 is kinnda unestable, vb doenst like threads :) but u can do it using the CreateThread API.
for example:


'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 Long

'the function i'm gonna use to launch the thread
Public Sub AThread()
    For i = 0 To 10
        Form1.Text1 = Form1.Text1 & "T2:" & i & vbCrLf
        Sleep (1000)
    Next i
End Sub

'in a form (form1) with 2 command buttons and a multinined textbox
Private Sub Command1_Click() 'click this button to start the thread
    hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf AsyncThread, ByVal 0&, ByVal 0&, hThreadID)
End Sub

Private Sub Command2_Click() 'click this to start a count, u will see it count while the thread is runnig,
                                              'so there are 2 counts at the same time
     For i = 0 To 10
        Form1.Text1 = Form1.Text1 & "T1:" & i & vbCrLf
        Sleep (1000)
        DoEvents
    Next i
End Sub

Private Sub Form_Unload(Cancel As Integer)
    CloseHandle hThread
    'If the thread is still running, close it
    If hThread <> 0 Then TerminateThread hThread, 0
End Sub

0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9776324
"but u can do it using the CreateThread API" This is for vb5 not vb6 vb 6 doesnt work consistantly with threads unless its an active x exe
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
withoutTen challenge 14 88
c# combobox autocomplete behavior 6 92
stringclean challenge 26 56
python sqlite question 11 42
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now