Sleep(10000) makes system unresponsive for 10 seconds.
|
|
Thread rating:  |
dos-man 64 - 27 Jun 2009 05:33 GMT How is it that a VBS script such as this:
Do Wscript.Sleep 10000 Loop
does not have any impact on the sytem?
I have a VB 5 app here calling Sleep 10000 in a loop, and it's not good.
Would using SleepEx( ) solve this problem?
To my knowledge, there are no windows in my application that need to process messages. There is only one form, and it isn't loaded.
dos-man
Alfie [UK] - 27 Jun 2009 22:46 GMT >How is it that a VBS script such as this: > [quoted text clipped - 11 lines] >To my knowledge, there are no windows in my application that need to >process messages. There is only one form, and it isn't loaded. Depends what you mean by 'does not have any impact on the system', 'its not good' and what you are trying to achieve?
In VB Sleep suspends the process/thread that your app is running within, in WSH Sleep suspends the calling script (but not the hosting mechanism). Whilst they are usually used in the same way to achieve the same type of goal, they're not strictly analogous.
SleepEx is used within VB when you're waiting on a callback (or asynchronous call) of some sort so that you can exit the 'sleep' state early.
So, we come back to what you're trying to achieve, why 'sleep', there may be a better mechanism to use?
 Signature Alfie [UK] <http://www.delphia.co.uk/> Hey man, that god complex is showing again.
Dos-Man 64 - 28 Jun 2009 01:45 GMT > On Fri, 26 Jun 2009 21:33:51 -0700 (PDT), dos-man 64 > [quoted text clipped - 16 lines] > > Depends what you mean by 'does not have any impact on the system', Doesn't slow down other applications or prevent the user from using other apps.
> 'its not good' Slows down other applications when my app is sleeping to the point that the browser can't load a webpage until my app wakes up.
> and what you are trying to achieve? The application just needs to do nothing for the amount of time that the user has specified.
> So, we come back to what you're trying to achieve, why 'sleep', there > may be a better mechanism to use? > -- > Alfie [UK] > <http://www.delphia.co.uk/> > Hey man, that god complex is showing again. I may end up having to loop with GetTickCount() and Doevents(), but I think it's rather pathetic that a function that literally doesn't do anything can't do it correctly ;(
Alfie [UK] - 29 Jun 2009 09:38 GMT >Doesn't slow down other applications or prevent the user from using >other apps. > >Slows down other applications when my app is sleeping to the point >that the browser can't load a webpage until my app wakes up. Sleep itself should not be causing the system to lock up, it only puts the calling thread into a kernel pause state, essentially blocking it from receiving it's CPU time slice (or receiving messages, etc), but should generally have no effect on other threads/processes.
>The application just needs to do nothing for the amount of time that >the user has specified. You may have more luck with a Sleep/DoEvents loop, something like;
Private Sub Pause(iSecs As Integer) Dim i As Integer For i = 1 To iSecs * 10 Sleep 100 DoEvents Next End Sub
...from http://preview.tinyurl.com/m35o2u
Keeping Sleep in small timeslices like this may avoid the issue you seem to be experiencing.
>I may end up having to loop with GetTickCount() and Doevents(), but I >think it's rather pathetic that a function that literally doesn't do >anything can't do it correctly ;( There are a couple of other possible solutions; Timers, CallBack Timers, SetWaitable Timers (http://support.microsoft.com/kb/q231298/), etc.
 Signature Alfie [UK] <http://www.delphia.co.uk/> Runtime Error 6D at 417A:32CF: Incompetent User.
Bob Butler - 29 Jun 2009 14:45 GMT >>Doesn't slow down other applications or prevent the user from using >>other apps. [quoted text clipped - 6 lines] > from receiving it's CPU time slice (or receiving messages, etc), but > should generally have no effect on other threads/processes. Not directly but it can if another process does something like a broadcast message; it's pretty easy to get Explorer to bog down and become unresponsive if you use a long Sleep call from a VB app.
Dos-Man 64 - 29 Jun 2009 17:19 GMT > >>Doesn't slow down other applications or prevent the user from using > >>other apps. [quoted text clipped - 10 lines] > message; it's pretty easy to get Explorer to bog down and become > unresponsive if you use a long Sleep call from a VB app. Does the behavior depend on what version of windows it is? I use 98. It's possible the end user may not have same problem using windows 2000 or whatever.
This is a scripting language, so it's important that scripts be able to sleep while waiting for a specific time to elapse.
*time.while[ne]("10:00 AM"); // keep looping until 10 AM { *time = ("~\@time~"); // check the time app.sleep("10"); // sleep for 10 seconds }
Alfie [UK] - 29 Jun 2009 23:41 GMT >Does the behavior depend on what version of windows it is? I use 98. >It's possible the end user may not have same problem using windows >2000 or whatever. Sleep should operate the same way, although I think that the minimum resolution may be dependant upon the default system timer frequency which was 55ms for Win95/98, so it may return within a tick boundary, but if you're measuring delay in seconds it shouldn't be that noticeable.
>This is a scripting language, so it's important that scripts be able >to sleep while waiting for a specific time to elapse. [quoted text clipped - 4 lines] > app.sleep("10"); // sleep for 10 seconds >} I take it thats a homebrew c-like script language?
We might need to a know a bit more about how your app is processing input, etc, to help work out where the problem is?
 Signature Alfie [UK] <http://www.delphia.co.uk/> If you put garbage in a computer you get garbage. But this garbage, having passed through a machine, is somehow ennobled and none dare criticize it.
Dos-Man 64 - 30 Jun 2009 00:40 GMT > On Mon, 29 Jun 2009 09:19:24 -0700 (PDT), Dos-Man 64 > [quoted text clipped - 19 lines] > > I take it thats a homebrew c-like script language? C was influential, but also PERL, VB, and DOS batch files. I have just changed the name of it to SNM. You can check it out, but this is the last version and has not been officially released yet. I'm trying to find an open source license that makes sense for a vb app. Might have to go the public domain route.
http://www.savefile.com/projects/808777638
> We might need to a know a bit more about how your app is processing > input, etc, to help work out where the problem is? Well, that's OK. I'm done messing around with this. I set it up to simply loop with doevents() and GetTickCount() until the time expires. Someone else can fix it when I release the vb 5 source code in the next few days. I'm bushed.
Dos-Man 64 - 30 Jun 2009 01:19 GMT > > On Mon, 29 Jun 2009 09:19:24 -0700 (PDT), Dos-Man 64 > [quoted text clipped - 27 lines] > > http://www.savefile.com/projects/808777638 Whoops. If anyone downloaded it, they will have to download it again. There was a problem with the setup program. I'm having trouble with the VB setup wizard right now, so I had to create a manual install for this using rapid-q.
I've had about 4 VB uninstalls and reinstalls over the past couple of years, and my system doesn't know which way is up anymore, heh. Way past due to format the old C: drive and get off to a fresh start.
Alfie [UK] - 30 Jun 2009 01:24 GMT >Well, that's OK. I'm done messing around with this. I set it up to >simply loop with doevents() and GetTickCount() until the time expires. >Someone else can fix it when I release the vb 5 source code in the >next few days. I'm bushed. I know that feeling, spent many a time wondering why my weekend vanished when working with some obstinate code. Glad you found a solution though, sometimes 'at least now it works' is enough :)
If you go open source post a link, might find a few regs in here or news:microsoft.public.vb.general.discussion who will offer some advice.
 Signature Alfie [UK] <http://www.delphia.co.uk/> A language that doesn't affect the way you think about programming is not worth knowing.
Dos-Man 64 - 30 Jun 2009 03:59 GMT > On Mon, 29 Jun 2009 16:40:52 -0700 (PDT), Dos-Man 64 > [quoted text clipped - 7 lines] > vanished when working with some obstinate code. Glad you found a > solution though, sometimes 'at least now it works' is enough :) Probably better off this way. I think the VB setup wizard stinks. You can use languages like rapid-q and autoit to create install programs. And you don't have to keep jumping through the same damn hoops over and over again.
> If you go open source post a link, might find a few regs in here or > news:microsoft.public.vb.general.discussion who will offer some [quoted text clipped - 3 lines] > <http://www.delphia.co.uk/> > A language that doesn't affect the way you think about programming is not worth knowing. I might try that. My problem is that I'm not sure if a VB app can actually qualify as open source. I mean you can't see the OS code, nor the code for the VB compiler. Seems like calling it open source is a bit of a stretch....
Dos-Man 64 - 02 Jul 2009 14:04 GMT > > On Mon, 29 Jun 2009 16:40:52 -0700 (PDT), Dos-Man 64 > [quoted text clipped - 5 lines] > > <http://www.delphia.co.uk/> > > A language that doesn't affect the way you think about programming is not worth knowing. Well, here it is. The final version of SNM. Compiles scripts to exe, too. God help anyone who tries to make sense of this source code because I can't even make any sense of it, but it works.
www.dos-man.webs.com
dos-man
Nobody - 30 Jun 2009 15:42 GMT Are you sure the form isn't loaded? If you access any property or method, the form is loaded. Try this code:
Public Sub PrintLoadedForms() Dim frm As Form
For Each frm In Forms Debug.Print "PrintLoadedForms: " & frm.name Next End Sub
Windows and some applications send some messages to all top level windows, including hidden windows. See SendMessage and the remarks about HWND_BROADCAST. Applications do this to detect and send information to other instances or talk to Add-ons. When a form is loaded, the window exists, but hidden. If in one event you are doing too much processing without calling DoEvents, other applications would be effected. These would appear to take too much time to start, because one or more top level windows are "hanged".
SendMessage: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx
Dos-Man 64 - 30 Jun 2009 17:25 GMT > Are you sure the form isn't loaded? If you access any property or method, > the form is loaded. Try this code: [quoted text clipped - 6 lines] > Next > End Sub I will try it. However, I tried physically unloading the form before calling sleep().
unload MainForm
for x = 1 to 6 sleep 10000 ' sleep for 60 seconds loop
Same effect.
Is it not true that vb apps have a hidden form? I suspect the hidden form is causing the problem.
Assuming I create a DLL in Delphi that Displays a form, my app would go into a dormant state until the form closes, would it not? What would happen if I would call sleep() from a DLL instead of the VB program?
Dos-Man 64 - 30 Jun 2009 18:26 GMT > > Are you sure the form isn't loaded? If you access any property or method, > > the form is loaded. Try this code: [quoted text clipped - 6 lines] > > Next > > End Sub Well, I tried it. It says that mainform is loaded.
printloadedforms sleep 10000
Then I tried unloading mainform. It says that mainform is not loaded.
unload mainform printloadedforms sleep 10000
In both cases, it still hijacks the machine for 10 seconds.
mr_unreliable - 30 Jun 2009 19:07 GMT >> How is it that a VBS script such as this: >> [quoted text clipped - 6 lines] >> I have a VB 5 app here calling Sleep 10000 in a loop, and it's not >> good. fwiw, wscript.sleep is not to be confused with the sleep api.
WScript.Sleep is not a wrapper for the api. Rather, it is a routine with a loop, such as has already been suggested. That is, it will sleep-a-bit and then then check for and process any outstanding messages, before sleeping some more.
This is more-or-less to protect scripters from committing sins which nobody here would ever think of. For example, so that a script will respond to a broadcast message such as a system shutdown message, that the scripter may not even know about.
cheers, jw
Dos-Man 64 - 30 Jun 2009 19:49 GMT On Jun 30, 1:07 pm, mr_unreliable <kindlyReplyToNewsgr...@notmail.com> wrote:
> >> How is it that a VBS script such as this: > [quoted text clipped - 22 lines] > > cheers, jw Ahhhh.. now it makes sense. That's kind of deceptive on their part to call the function sleep() when it is "awake" (and using resources) for at least part of the time. I've renamed my function to wait().
Thank you for the info.
dos-man
Bob Butler - 30 Jun 2009 22:14 GMT <cut>
> This is more-or-less to protect scripters from committing > sins which nobody here would ever think of. Like doing "Wscript.Sleep 10000" ? <g>
|
|
|