[vb.net] Simple multithreaded instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.