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.
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
To make serveral threads in VB, you need a single API call and a few constants (this code should be placed in a module)
:<br><br>
Public Const CTF_COINIT = &H8<br>
Public Const CTF_INSIST = &H1<br>
Public Const CTF_PROCESS_REF = &H4<br>
Public Const CTF_THREAD_REF = &H2<br><br>
Declare Function SHCreateThread Lib "shlwapi.dll" (ByVal pfnThreadProc As Long, pData As Any, ByVal dwFlags As Long, ByVal pfnCallback As Long) As Long<br><br>
Next is to make sub for the thread (it will not work for a private).<br><br>
public sub myNewThread()<br>
dim i as integer<br><br>
for i = 0 to 99<br>
debug.print "message from a new thread (" & i & ")"<br>
next i<br>
end sub<br><br>
Last but not least, all you need to do, is invoke the new thread:
SHCreateThread AddressOf myNewThread, ByVal 0&, CTF_INSIST, ByVal 0&<br><br>
That's it.<br><br>You have a new thread (make sure to end the sub before you exit the program or vb will crash.)
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine