Login | |
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/22/2007 8:46:38 AM
|
|
 |
|
| |
Fredledingue
Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
It's the kind of trick which is very simple, very easy to code but, for some reason, you never thought about before.
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/25/2007 5:31:22 AM
|
|
 |
|
| |
TNO
Posts: 1066
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Wouldn't this method work a well? quote:
<html> <head> <script type="text/vbscript"> Sub Sleep(t,i) MyTime = DateAdd(i,t,Now) While Now < MyTime 'Do Nothing and Loop Wend MsgBox "Done" End Sub </script> </head> <body> <button onclick="Sleep 5,'s'">Go</button> </body> </html>
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/25/2007 10:39:34 AM
|
|
 |
|
| |
Fredledingue
Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
Yes and no. It will wait but these lines... While Now < MyTime 'Do Nothing and Loop Wend ...will cause a 100% processor usage during all the waiting time. (I'v tested it) Other crazy methods using a "ping" command line, also cause the same processor activity. This is not the intended effect of a "sleep". usualy you want a sleep when the computer needs resources for another task. Not to block these resources in a loop. The irony is that you can't put "WScript.sleep" inside the loop to avoid that! Only the swcript.sleep methods realy pauses the script. The downside of it in Hta is that everytime you want a sleep, you have to launch wscript.exe which is not very low-resource friendly. Especialy if you want very short sleeps, like 50 milliseconds. But it works well for larger sleeps (500 ms or more).
< Message edited by Fredledingue -- 6/25/2007 11:12:34 AM >
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/26/2007 5:03:03 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
quote:
ORIGINAL: Fredledingue The TechGuy tells us to use the setInterval method... no no no: Tha'ts not a "Sleep". A real Sleep is this: <snipped shell.Run method> Just out of curiosity, why do you say that the setInterval is not a "Sleep"? The CPU usage doesn't spike as it does when you run an external script... sure you ahve to be careful with your code, but it works... Having used both methods in HTAs, I think i like the setinterval method better, due to the lower amount of code/OS interaction required.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/26/2007 5:54:44 AM
|
|
 |
|
| |
Fredledingue
Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
The setInterval is not a Sleep: it's a repetition of a subroutine. You can't make a script sleeping with that method: you can only launch a script after a given interval. To imitate a sleep with setInterval you need to slice your code into as many subs as you have sleeps and clear the interval after the sub has ran once. Technicaly that's better if you have only one or two sleep lines in your code, not if you have two dozen of them and, even worse, don't know exactely where to position them in the line order. I had the case with a very long script where I had to test the sleep a few line up or a few lines down. Very difficult to do with setInterval. Note that the setInterval can be very useful in other cases. To set up a progressbar for example.
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/26/2007 1:50:47 PM
|
|
 |
|
| |
wanghuok
Posts: 17
Score: 0
Joined: 10/13/2005
Status: offline
|
Why not use wscript.sleep directly, What is the advantage as you done.
_____________________________
I come from China,This is a very beautiful country. Welcome to China.
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/26/2007 8:04:53 PM
|
|
 |
|
| |
wanghuok
Posts: 17
Score: 0
Joined: 10/13/2005
Status: offline
|
Oh.Thank you I understand.
_____________________________
I come from China,This is a very beautiful country. Welcome to China.
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/27/2007 12:19:00 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
quote:
ORIGINAL: Fredledingue The setInterval is not a Sleep: it's a repetition of a subroutine. You can't make a script sleeping with that method: you can only launch a script after a given interval. To imitate a sleep with setInterval you need to slice your code into as many subs as you have sleeps and clear the interval after the sub has ran once. Technicaly that's better if you have only one or two sleep lines in your code, not if you have two dozen of them and, even worse, don't know exactely where to position them in the line order. I had the case with a very long script where I had to test the sleep a few line up or a few lines down. Very difficult to do with setInterval. Good point, hadn't thought of it that way. quote:
ORIGINAL: Fredledingue Note that the setInterval can be very useful in other cases. To set up a progressbar for example.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/28/2007 12:54:27 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
While I am not certain that number of pings = time in seconds, I will agree that it does NOT cause 100% CPU usage... unless maybe you are running on a 386/16, in which case, you have more problems than trying to get a sleep function in an HTA.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/29/2007 4:30:42 AM
|
|
 |
|
| |
Fredledingue
Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
I tested the cod posted by Gignolar: There is a spike to 100% during one second or two then, cpu usage is back to normal or only lightly higher. Previousely I tried the address: 1.1.1.1, as given in the example where I found it. With this address there is a cpu use of 100% all the time. So the address you use is important. However xith WshShell.Run "sleeper.vbs " & strSeconds, 1, true there is no detectable cpu use increase. So I conclude that it's still a better option.
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 6/29/2007 5:33:22 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
The point was to ping the lookback address. You aren't really looking for any response, you are just trying to get something to take up some time. So, rather than ping an address that you may or may not have access to, ping 127.0.0.1 - as long as you have a nic and Ip installed, it'll be there.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 7/1/2007 6:52:51 PM
|
|
 |
|
| |
ginolard
Posts: 1024
Score: 21
Joined: 8/10/2005
Status: offline
|
Also, this is a Sleep function we're talking about. How often do you need to sleep for exactly x number of seconds?? More often than not you just want to sleep for enough time that whatever was running, finishes running. The ping method may not run for exactly the number of seconds you specify, I don't know, I never tested it. But if I say "sleep for 5 seconds" and it sleeps for 6, I really don't mind.
_____________________________
Author of ManagePC - http://managepc.net AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
|
|
| |
|
|
|
 |
RE: Sleep in HTA: not a dream anymore! - 7/6/2007 11:00:55 AM
|
|
 |
|
| |
Fredledingue
Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
From the few tests I made, the time was relatively acurate, at human scale.
_____________________________
Fred
|
|
| |
|
|
|
|
|