ADVERTISEMENT
ADVERTISEMENT

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

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.

'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



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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.