VB.Net program to Pause a Thread

Here, we are going to learn how to Pause a Thread in VB.Net?
Submitted by Nidhi, on January 04, 2021 [Last updated : March 08, 2023]

How to pause a thread in VB.Net?

To pause a thread in Vb.Net, we need to use Thread.Sleep() method, this method takes an argument in milliseconds to pause the thread.

Program/Source Code:

The source code to Pause a Thread is given below. The given program is compiled and executed successfully.

VB.Net code to Pause a Thread

'Program to Pause a Thread in VB.Net

Imports System.Threading

Module Module1
    Sub Main()
        For loopVar = 1 To 5 Step 1
            Console.WriteLine("Sleep Main thread for 1 Second")
            Thread.Sleep(1000)
        Next

        Console.WriteLine("Main thread Finished")
    End Sub
End Module

Output

Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Main thread Finished
Press any key to continue . . .

Explanation

In the above program, we imported the System.Threading namespace to implement multithreading in the program. After that, we created a module Module1. The Module1 contains a Main() function.

The Main() function is the entry point for the program. Here, we sleep the Main thread for 1 second using the Sleep() method of Thread class. The argument of the Sleep() method is to accept values in a millisecond.

VB.Net Threading Programs »





All VB.Net Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.