ADVERTISEMENT
ADVERTISEMENT

VB.Net program to print the elapsed milliseconds of stopwatch using Thread.Sleep() method

Here, we are going to learn how to print the elapsed milliseconds of stopwatch using Thread.Sleep() method in VB.Net?
Submitted by Nidhi, on January 04, 2021

To solve the above problem, here we paused the program using Thread.Sleep() and then print elapsed milliseconds using ElapsedMilliseconds property of StopWatch class.

Program/Source Code:

The source code to print the elapsed milliseconds of stopwatch using Thread.Sleep() method is given below. The given program is compiled and executed successfully.

'Vb.Net program to print the elapsed milliseconds of 
'stopwatch using Thread.Sleep() method.

Imports System.Threading

Module Module1
    Sub Main()
        Dim watch As Stopwatch = Stopwatch.StartNew()

        Thread.Sleep(2000)
        watch.Stop()

        Console.WriteLine("Elapsed Milliseconds by ThreadSleep() : {0}", watch.ElapsedMilliseconds)
    End Sub
End Module

Output:

Elapsed Milliseconds by ThreadSleep() : 2007
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 Main() function.

The Main() is the entry point for the program, here we created the object of Stopwatch class using StartNew() method of StopWatch class. After that, we slept the thread for 2000 milliseconds using the Sleep() method and then stop the thread and print the elapsed time in milliseconds using the ElapsedMilliseconds property of Stopwatch class on the console screen.

VB.Net Threading Programs »



ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
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.