简体   繁体   中英

Delay an application in vb.net

Hey I am new to Visual Studio 2012 (I'm using vb.net) and is there any way to delay the macro for a certain amount of time? I have tried "Application.Wait" but it doesn't work.

Assuming you're only using a single thread...

Imports System.Threading 'Credit to @Force - thank you

Thread.Sleep(ms)

I'm not sure if you're looking for something that simple or not.


Or you can add:

Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

And simply call Sleep(ms).

'ms' being the number of milliseconds you want to wait (1000ms = 1 second).

Unless you want to freeze your UI, it's not a good practice to sleep the main thread. Instead put your delay in a separate thread, and delay only on the separate thread. Better yet, put some loader/progress indicator to let the user know, that some background process is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM