Trả lời mọi thắc mắc của bạn


Liệt kê những bài viết mới nhất

Bài viết mớiNgười viếtVào lúc
paltalk code
Sun Mar 06, 2016 1:28 am
vb ListView
Sun Mar 06, 2016 1:00 am
Find occurent of character in string nth
Sat Jan 16, 2016 10:48 pm
Send listbox items to textbox
Wed Jan 13, 2016 9:55 pm
[VB] Find word in listbox items
Wed Jan 13, 2016 7:55 pm
code cho hint2
Wed Jan 13, 2016 3:22 pm
[vb] Font RTB
Tue Dec 29, 2015 10:29 am
[vb] selected text RTB
Tue Dec 29, 2015 9:06 am
[vb] send unicode text
Tue Dec 29, 2015 9:03 am
[vb] format multi richtextbox
Tue Dec 29, 2015 9:01 am
Trang web tai cac bang sang che
Mon Dec 28, 2015 1:28 pm
[VB] Sử dụng resource của chính chương trình
Sat Dec 26, 2015 8:56 pm
[vb] Phân biệt class và Module
Thu Dec 24, 2015 2:39 pm
[VB] MY API and Functions declaration
Mon Dec 21, 2015 1:45 pm
[vb] Khai báo và sử dụng hàm Setforeground
Mon Dec 21, 2015 1:29 pm
[VB] Sử dụng hàm Sendmessage để gửi tiếng việt, và format richtextbox
Mon Dec 21, 2015 1:26 pm
[VB] Find menu context handle/ID by SPY++
Fri Dec 18, 2015 1:20 pm
[VB] Find menu context handle/ID - Vu Hai Ninh
Fri Dec 18, 2015 1:00 pm
[VB] Find menu context handle/ID
Fri Dec 18, 2015 12:54 pm
[VB] Sleep in VB program
Thu Dec 17, 2015 7:48 pm
[VB] CLose window if found
Wed Dec 16, 2015 7:07 pm
[VB] Không cho thay đổi kích cỡ form khi chạy
Wed Dec 16, 2015 3:28 pm
[VB] Không cho thay đổi text box khi chạy
Wed Dec 16, 2015 3:22 pm
[VB] Tìm cửa sổ và Button bằng FindWindow & FindWindowsEx
Wed Dec 16, 2015 3:16 pm
[VB] Xóa text mặc định của text box khi click
Wed Dec 16, 2015 3:12 pm


You are not connected. Please login or register

[VB] Sleep in VB program

Go down  Message [Page 1 of 1]

1[VB] Sleep in VB program Empty [VB] Sleep in VB program Thu Dec 17, 2015 7:48 pm

HdAd

HdAd
Admin

Sleep causes a program to suspend operation. This Subroutine receives one parameter, which indicates the number of milliseconds to pause the program. No CPU time is used by Sleep. The program simply ceases to operate.
Example. This example program invokes the Sleep method on the Thread type. Please note how the Imports System.Threading line is included at the top of the program text. This enables the program to compile correctly.
Calls:Sleep(0) pauses the program for zero milliseconds. Sleep(5000) pauses for five seconds. Sleep(1000) pauses for one second.

Also, the SpinWait method is used. This subroutine results in a lot of CPU usage based on the large integer passed to it. SpinWait is the opposite of a Sleep call. It pegs the CPU at 100%.
VB.NET program that demonstrates the Sleep method

Imports System.Threading

Module Module1

Sub Main()
' Create a Stopwatch and sleep for zero milliseconds.
Dim stopwatch As Stopwatch = stopwatch.StartNew
Thread.Sleep(0)
stopwatch.Stop()

' Write the current time.
Console.WriteLine(stopwatch.ElapsedMilliseconds)
Console.WriteLine(DateTime.Now.ToLongTimeString)

' Start a new Stopwatch.
stopwatch = stopwatch.StartNew
Thread.Sleep(5000)
stopwatch.Stop()
Console.WriteLine(stopwatch.ElapsedMilliseconds)
Console.WriteLine(DateTime.Now.ToLongTimeString)

' Start a new Stopwatch.
stopwatch = stopwatch.StartNew
Thread.Sleep(1000)
stopwatch.Stop()
Console.WriteLine(stopwatch.ElapsedMilliseconds)

' Start a new Stopwatch and use SpinWait.
stopwatch = stopwatch.StartNew
Thread.SpinWait(1000000000)
stopwatch.Stop()
Console.WriteLine(stopwatch.ElapsedMilliseconds)
End Sub

End Module

Output

0
9:36:02 AM
4999
9:36:07 AM
999
3128


Summary. To use the Thread.Sleep or Thread.SpinWait methods, please include the Imports System.Threading namespace. The Thread.Sleep method receives an integer indicating the number of milliseconds you want the program execution to pause.
Note:The Thread.SpinWait method receives an integer indicating the amount of work to do. This results in 100% CPU usage.
Integer

https://hoidap.forumotion.com

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum