Imports System.Threading
Public Class ThreadTest
Public Sub EjecutarThreads()
'definir el thread 1
Dim tr1 As New Thread(AddressOf Thread1)
'definir el thread 2
Dim tr2 As New Thread(AddressOf Thread1)
'Iniciar thread 1
tr1.Start()
'Iniciar thread 2
tr2.Start()
MsgBox("Los threads se estan ejecutando")
End Sub
Public Sub Thread1()
'Aca va el codigo de uno de los Thread
Dim i As Integer
Debug.WriteLine("Ejecutanto Thread 1")
For n As Integer = 0 To 1000000000
i = n
'Esto pone en pausa el thread la cantidad de milisegundos
'indicada en el parametro.
'Si el valor es cero, bloquea temporalmente el thread para
'permitir la ejecucion de otros threads en espera.
'Se puede obviar pero conviene incorporarlo para no llevar
'el uso del procesador al 100%
Thread.CurrentThread.Sleep(0)
Next
Debug.WriteLine("Thread 1 Terminado")
End Sub
Public Sub Thread2()
'Aca va el codigo de otro de los Thread
Dim i As Integer
Debug.WriteLine("Ejecutanto Thread 2")
For n As Integer = 0 To 1000000000
i = n
Thread.CurrentThread.Sleep(0)
Next
Debug.WriteLine("Thread 2 Terminado")
End Sub
End Class