VBScript Sleep

I’ve just had a requirement for a sleep command in ASP, apparently there isn’t one (not that I can find). There is a Wscript.Sleep for command line VBS’s but nothing in ASP.

So, I’ve written a really quick simple one that some might find useful –

Sub Sleep(intSecs)
Dim dtStart, boolDone
dtStart = now()
boolDone = False
While Not boolDone
If DateDiff("s",dtStart,now()) >= cint(intSecs) Then
boolDone = True
End If
Wend
End Sub

Update: As noted in the comments, this really *shouldn’t* be used as it pins your CPU. If you must use it, please be aware of what it’s doing.

Advertisements

5 Responses to “VBScript Sleep”

  1. Aaron Says:

    Awesome. I can now empbed a sleep function inside my wise packages. Thanks a million!

  2. dj Says:

    your pinning your cpu this way, not good. change. please.

  3. osblues Says:

    Thanks for your comment DJ, to be honest I’ve not used this one (or had a need for it) in ages. Do you have a way that doesn’t pin the CPU? I’ll have a think.. (I don’t really do much classic ASP anymore).

  4. Nripin Says:

    Thanks very much works very well

  5. Michael Strorm Says:

    Yeah, I’m sorry, but dj is right. While this technique works in theory, it’s a very bad idea in practice.

    Although it works, it’ll force your CPU (or core) usage up to 99 or 100%, ironically when the code is meant to be doing *nothing*! Very strongly NOT recommended.

    It’s a PITA that classic ASP doesn’t appear to have a proper Sleep command.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: