devxlogo

Wait for 1 second

Question:
I have a place in my Active Server Page script (VBScript) where I’d like to wait for 1 second before performing an action. What can one do to cause a script to pause for 1 second (without wasting CPU in some huge “For…” loop)?

Answer:
If all you want to do is wait, I’ve got a really simple answer. Call the Sleep API.

   Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)   Call Sleep(1000)

This will put your application into a hibernation-like mode, as it will not do anything (respond to the user, paint itself, fire events, etc.) until the call returns. This call is designed to conserve CPU cycles during periods when an application doesn’t need to be active.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.