Creating Threads in VB.NET

In this article you will learn how to create a simple Single Thread in VB.NET.
  • 17012
In computer science thread means a sequence of execution instructions that can run independently , that is a single flow of execution in a process. Thread is like a process, at least one thread exists within each process. Threading can be categorize into single or multithreading threading. Single thread means that only one task can execute and at the same time the other tasks have to wait for the completion of the current task like in a queue. Look at the following example to create a simple thread in VB.NET:

Module Module1
    Sub TaskA()
        Dim I As Integer
        For I = 0 To 10
            Console.Write("A")
        Next
        Console.WriteLine()
    End Sub
    Sub TaskB()
        Dim I As Integer
        For I = 0 To 10
            Console.Write("B")
        Next
        Console.WriteLine()
    End Sub
    Sub TaskC()
        Dim I As Integer
        For I = 0 To 10
            Console.Write("C")
        Next
    End Sub

    Sub Main()
        Dim A As System.Threading.Thread = New Threading.Thread(AddressOf TaskA)
        Dim B As System.Threading.Thread = New Threading.Thread(AddressOf TaskB)
        Dim C As System.Threading.Thread = New Threading.Thread(AddressOf TaskC)
        A.Start()
        B.Start()
        C.Start()
        Console.ReadLine()
    End Sub
End Module

OUTPUT:
 

threading.gif

Here we create three simple threads to just understand how to create a Single Thread in VB.NET. 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.