Tools Links Login

Easy multithread in VB (Updated)

Its actualy quite easy to make several threads in VB. All you need is one (1), API call and you're on your way.

Original Author: Thomas Raben

Code

To make serveral threads in VB, you need a single API call and a few constants (this code should be placed in a module)
:


Public Const CTF_COINIT = &H8

Public Const CTF_INSIST = &H1

Public Const CTF_PROCESS_REF = &H4

Public Const CTF_THREAD_REF = &H2


Declare Function SHCreateThread Lib "shlwapi.dll" (ByVal pfnThreadProc As Long, pData As Any, ByVal dwFlags As Long, ByVal pfnCallback As Long) As Long


Next is to make sub for the thread (it will not work for a private).


public sub myNewThread()

dim i as integer


for i = 0 to 99

debug.print "message from a new thread (" & i & ")"

next i

end sub


Last but not least, all you need to do, is invoke the new thread:
SHCreateThread AddressOf myNewThread, ByVal 0&, CTF_INSIST, ByVal 0&


That's it.

You have a new thread (make sure to end the sub before you exit the program or vb will crash.)

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 99 times

Categories

Visual Basic 6

Attachments

Easy_multi553822152002.zip
Posted: 9/3/2020 3:45:00 PM
Size: 2,511 bytes


Comments

No comments have been added for this post.

You must be logged in to make a comment.