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 »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.