1. Imports System2. Imports System.Threading3. 4. 5. Module Module16. 7.SubMain ()8. 9.DimMythread1 asThreadTen.DimMythread2 asThread One.DimMythread3 asThread A.'To create a thread object -. Mythread1 =NewThread (AddressOfMythreadrun) -. Mythread2 =NewThread (AddressOfMythreadrun) the. Mythread3 =NewThread (AddressOfMythreadrun) -. Console.WriteLine (Now.tolongtimestring &"Thread object created, start thread execution") -.'Execution Thread -. Mythread1. Start ("Thread 1") +. Mythread2. Start ("Thread 2") -. Mythread3. Start ("Thread 3") +.'wait for thread to finish A. Mythread1. Join () at. Mythread2. Join () -. Mythread3. Join () -.'Thread Execution Complete -. Console.WriteLine (Now.tolongtimestring &"thread execution finished!") -.End Sub -. Public SubMythreadrun (ByValData as Object) in. Console.WriteLine (Data &","& Now.tolongtimestring &"Execution") -.End Sub to. EndModule
The Dim mythread1 as thread Initializes a new instance of the thread class, specifying a delegate that allows the object to be passed to the thread when it is started.
threads do not start executing when they are created. to dispatch a thread for execution, call the Start method.
The above code creates 3 thread objects and then calls their start method to execute them.
Call the Join method and wait for them to execute.
You can create a new console application in vb.net2010, and then write the above code in the module
A function in the New thread (AddressOf Mythreadrun) constructor that must be performed as a thread is passed as a parameter
Mythread1. Start ("Thread 1") the Start method can pass parameters to the thread as it executes
Imports System Imports System.Threading
[vb.net] Simple multithreaded instance