Windows API Sleep function 
Author Message
 Windows API Sleep function

I've seen some of the correspondence on the Sleep
function using the following code:

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

Call Sleep(10000)
----

However, I have found a problem using this code
and I wonder if anyone can suggest a work around.

I'm writing an application that sits around in the
background and I want it to fire up every say 15
minutes to do something.  I've done it by having a
do loop with this Sleep command in it.

However, doing something completely unrelated, I
then find that within Windows file explorer, if I
click on a file (say *.doc) then everything hangs
until a 15 minute sleep cycle is over and then MS
Word opens.  It's as if my background program has
told the whole of Windows to sleep....

any suggestions?

Thanks

Griff

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Sun, 03 Mar 2002 03:00:00 GMT  
 Windows API Sleep function
Instead of using sleep, use a timer set to 60000 (1 minute, Timer had max
interval of 65,535) and count up to 15 in the timer.  Then when you get to
15 reset the counter back to 1 then run your 15 minute interval code.
Quote:

>I've seen some of the correspondence on the Sleep
>function using the following code:

>----
>Public Declare Sub Sleep Lib "kernel32" (ByVal
>dwMilliseconds As Long)

>Call Sleep(10000)
>----

>However, I have found a problem using this code
>and I wonder if anyone can suggest a work around.

>I'm writing an application that sits around in the
>background and I want it to fire up every say 15
>minutes to do something.  I've done it by having a
>do loop with this Sleep command in it.

>However, doing something completely unrelated, I
>then find that within Windows file explorer, if I
>click on a file (say *.doc) then everything hangs
>until a 15 minute sleep cycle is over and then MS
>Word opens.  It's as if my background program has
>told the whole of Windows to sleep....

>any suggestions?

>Thanks

>Griff

>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.



Sun, 03 Mar 2002 03:00:00 GMT  
 Windows API Sleep function
If you are using VB6, try creating and API timer and a callback event.
Alan
Quote:

> I've seen some of the correspondence on the Sleep
> function using the following code:

> ----
> Public Declare Sub Sleep Lib "kernel32" (ByVal
> dwMilliseconds As Long)

> Call Sleep(10000)
> ----

> However, I have found a problem using this code
> and I wonder if anyone can suggest a work around.

> I'm writing an application that sits around in the
> background and I want it to fire up every say 15
> minutes to do something.  I've done it by having a
> do loop with this Sleep command in it.

> However, doing something completely unrelated, I
> then find that within Windows file explorer, if I
> click on a file (say *.doc) then everything hangs
> until a 15 minute sleep cycle is over and then MS
> Word opens.  It's as if my background program has
> told the whole of Windows to sleep....

> any suggestions?

> Thanks

> Griff

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.



Sun, 03 Mar 2002 03:00:00 GMT  
 Windows API Sleep function

Quote:

>I've seen some of the correspondence on the Sleep
>function using the following code:

>----
>Public Declare Sub Sleep Lib "kernel32" (ByVal
>dwMilliseconds As Long)

>Call Sleep(10000)
>----

Jeff who is having a BAD day replies to ALL the tosh replies to this
post. What a load of <deleted>.

Pause = Timer + 15 * 60 ' snooze for 15 minutes in seconds
Do until Timer > Pause
        DoEvents        ' let other app get some processor time
Loop

' Timer returns number of seconds since midnight.
' So don't run it at 23:45 hrs :-)

Jeff



Tue, 05 Mar 2002 03:00:00 GMT  
 Windows API Sleep function
Putting DoEvents in a tight loop will really hog CPU time, and slow down
every other running process. You need DoEvents AND a short Sleep to keep
your app responsive but not greedy:

Do until Timer > Pause
    DoEvents
    Sleep 100
Loop

That way your application wakes up every 100ms, has a look around to see if
anything needs doing, then goes back to sleep again (much like me in fact!)

My news server (a proxy) doesn't have any of the other replies, so sorry if
this has already been pointed out.

    RobS

--

Quote:
> Jeff who is having a BAD day replies to ALL the tosh replies to this
> post. What a load of <deleted>.
[snip]
> Do until Timer > Pause
> DoEvents ' let other app get some processor time
> Loop



Tue, 05 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Windows Sleep API call Help.

2. Problems after calling WaitForSingleObject and Sleep API functions

3. WinSock problem, Api-Sleep Function blocks the DataArrival-Event

4. WinSock problem, Api-Sleep Function blocks the DataArrival-Event

5. API Sleep Function Question

6. Can anyone send Sleep API function implimentation code in VB

7. WinSock problem, Api-Sleep Function blocks the DataArrival-Event

8. One of two functions doesn't function on Windows 95 (i does on Windows NT)

9. I need Windows 3.11 API / Necesito API de Windows 3.11

10. I need Windows 3.11 API / Necesito API de Windows 3.11

11. Calling Windows API functions with string parameters from Access

12. Does VB.NET supports every Windows API function?

 

 
Powered by phpBB® Forum Software