Aquí te adjunto un ejemplo que te servirá :
MODULO.BAS :
'Estructura necesaria para la llamada a la función
'CreateThread. En C se puede dar un valor NULL para
'que tome valores por defecto. En VB hay que pasar
'la estructura completa aunque sea con valores por
'defecto para que la cosa chute.
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Dim SecStruc As SECURITY_ATTRIBUTES
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Sub CrearThread()
' Damos valores a los campos de la estructura
' SECURITY_ATTRIBUTES
' Adjunto la explicación extraída del help del
' API de Microsoft C++.
'Especifica el largo en bytes de esta estructura
'El valor será establecido al tamaño de la estructura SECURITY_ATTRIBUTES
SecStruc.nLength = 12
SecStruc.lpSecurityDescriptor = 0
' Points to a security descriptor for the
' object that controls the sharing of it.
' If NULL is specified for this member,
' the object may be assigned the default
' security descriptor of the calling process.
SecStruc.bInheritHandle = True
' Specifies whether the returned handle is
' inherited when a new process is created.
' If this member is TRUE, the new process
' inherits the handle.
' Por fín creamos las hebras. Nótese que en
' el tercer parámetro le especificamos el
' puntero a la función o procedimiento a
' ejecutar al arrancar la hebra (usamos el
' operador AddressOf propio del VB5).
' En el cuarto parámetro se le especifica el
' parámetro que recibirá la función o el
' procedimiento.
' Por cierto, he estado probando con parámetros
' tipo string y no he conseguido que funcione
' bien. Curiosamente la primera hebra no pasa
' correctamente el parámetro, y en cambio la
' segunda sí. Si alguien encuentra una explicación
' le agradeceré que me la dé, aunque seguiré
' investigando por mi cuenta.
param1& = 1
m_hThread1& = CreateThread(SecStruc, 0, AddressOf Hilo1, ByVal param1&, 0, dwThreadId1&)
param2& = 2
m_hThread2& = CreateThread(SecStruc, 0, AddressOf Hilo2, ByVal param2&, 0, dwThreadId2&)
param2& = 3
m_hThread2& = CreateThread(SecStruc, 0, AddressOf Hilo3, ByVal param2&, 0, dwThreadId2&)
End Sub
Sub Hilo1()
Static ContadorA As Integer
ContadorA = ContadorA + 1
Form1.Text1.Text = ContadorA
End Sub
Sub Hilo2()
Static ContadorB As Integer
ContadorB = ContadorB + 1
Form1.Text2.Text = ContadorB
End Sub
Sub Hilo3()
Static ContadorC As Integer
ContadorC = ContadorC + 1
Form1.Text3.Text = ContadorC
End Sub
'Call ExitThread(ByVal 0)
FORMULARIO :
Private Sub Form_Load()
Call CrearThread
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
End Sub
Private Sub Timer1_Timer()
Call Hilo1
End Sub
Private Sub Timer2_Timer()
Call Hilo2
End Sub
Private Sub Timer3_Timer()
Call Hilo3
End Sub