Solved

How to run multiple threads in VB???

Posted on 2003-11-17
7
1,071 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 266
SCRIPT65535: Unexpected call to method or property access video html 5 explorer 3 107
Java array 10 89
Eclipse neon2 "Java build path" correctness 7 44
A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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