Reducing Load on CPU in Access - Sleep API? 
Author Message
 Reducing Load on CPU in Access - Sleep API?

I have a database that runs through a loop checking for new data coming (SMS
Messages) in to the system via a connect phone and a windows 2000 service
that adds the messages of incoming data

I've used the DoEvents command to release Access and pass control to the
operating system which has been a great help by it's still using 100% of the
CPU's processing power

I've checked passed newsgroup postings and the Sleep API is mentioned .. I
assume it is this code from below:

http://www.*-*-*.com/
(also pasted below)

But when I paste this code into my application I get the error message upon
running the test
"only comments may appear after end sub."

Is this the Sleep API I've seen mentioned on previous postings?

And also the correct way to make use of it?

I want to add about a quarter to half second delay in my loops to free up
the CPU

'***************** Code Start *******************
Private Declare Sub sapiSleep Lib "kernel32" Alias "Sleep" (ByVal
dwMilliseconds As Long)

Sub sSleep(lngMilliSec As Long)
    If lngMilliSec > 0 Then
        Call sapiSleep(lngMilliSec)
    End If
End Sub

Sub sTestSleep()
Const cTIME = 1000 'in MilliSeconds
    Call sSleep(cTIME)
    MsgBox "Before this Msgbox, I was asleep for " & cTIME & "
Milliseconds."
End Sub
'***************** Code End *********************



Sun, 09 Jan 2005 09:16:08 GMT  
 Reducing Load on CPU in Access - Sleep API?
Where have you pasted this code?
Try creating a new module (Modules tab of Database window), and pasting the
whole thing in there. Generally the "Private Declare Sub" would go above
any other procedures, at the top of the module with the "Option" lines.
Save the module with a different name--say "basSleep".

The DoEvents causes Access to yield processing power. If there is nothing
else wanting that processing power, Windows will return the CPU to Access,
and so the loop will appear to use 100%. If you start another CPU-intensive
process while that loop is running, you should see the percentage used by
Access fall dramatically.

The API call is really only needed if you want fine control over the length
of the delay. If you're happy with a delay that could be up to a second
out, you could create your own loop in Access like this:

Function Delay(Seconds As Long)
    Dim dtNow As Date

    dtNow = Now()
    Do While DateDiff("s", dtNow, Now()) < Seconds
        DoEvents
    Loop
End Function

The only disadvantage I can think of would be if the workstation had its
clock adjusted wildly by a time server while the delay was running.

--
Allen Browne - Microsoft MVP (Most Valuable Professional)
Allen Browne's Database And Training - Perth, Western Australia.
Tips for MS Access users - http://allenbrowne.com
Reply to the newsgroup. (Email address has spurious "_SpamTrap")


Quote:
> I have a database that runs through a loop checking for new data coming
(SMS
> Messages) in to the system via a connect phone and a windows 2000 service
> that adds the messages of incoming data

> I've used the DoEvents command to release Access and pass control to the
> operating system which has been a great help by it's still using 100% of
the
> CPU's processing power

> I've checked passed newsgroup postings and the Sleep API is mentioned ..
I
> assume it is this code from below:

> http://www.mvps.org/access/api/api0021.htm
> (also pasted below)

> But when I paste this code into my application I get the error message
upon
> running the test
> "only comments may appear after end sub."

> Is this the Sleep API I've seen mentioned on previous postings?

> And also the correct way to make use of it?

> I want to add about a quarter to half second delay in my loops to free up
> the CPU

> '***************** Code Start *******************
> Private Declare Sub sapiSleep Lib "kernel32" Alias "Sleep" (ByVal
> dwMilliseconds As Long)

> Sub sSleep(lngMilliSec As Long)
>     If lngMilliSec > 0 Then
>         Call sapiSleep(lngMilliSec)
>     End If
> End Sub

> Sub sTestSleep()
> Const cTIME = 1000 'in MilliSeconds
>     Call sSleep(cTIME)
>     MsgBox "Before this Msgbox, I was asleep for " & cTIME & "
> Milliseconds."
> End Sub
> '***************** Code End *********************



Sun, 09 Jan 2005 10:23:54 GMT  
 Reducing Load on CPU in Access - Sleep API?


Quote:
> Save the module with a different name--say "basSleep".

bahSleep?


Sun, 09 Jan 2005 13:25:22 GMT  
 Reducing Load on CPU in Access - Sleep API?
Don P. Mellon wrote

 > > Save the module with a different name--say "basSleep".

 > bahSleep?

Sure, like the TV program, remember it, "bah, bah, blacksleep".



Mon, 10 Jan 2005 03:30:59 GMT  
 Reducing Load on CPU in Access - Sleep API?
On Wed, 24 Jul 2002 02:16:08 +0100, "Diamond"

Quote:

>I've used the DoEvents command to release Access and pass control to the
>operating system which has been a great help by it's still using 100% of the
>CPU's processing power
>I've checked passed newsgroup postings and the Sleep API is mentioned .. I
>assume it is this code from below:

Yeah.

If you want to check for an event every n seconds, you could also use
the Timer control on a form. I actually prefer this method than using
sleep.

Quote:
>But when I paste this code into my application I get the error message upon
>running the test
>"only comments may appear after end sub."

Paste the code below in an empty module and you should be okay.


Mon, 10 Jan 2005 04:42:08 GMT  
 Reducing Load on CPU in Access - Sleep API?


Quote:
> Don P. Mellon wrote

>  > > Save the module with a different name--say "basSleep".

>  > bahSleep?

> Sure, like the TV program, remember it, "bah, bah, blacksleep".

This "bas" stuff reminds me of something from a long time ago.  Some sort of
text editor I once used.  God.  I just can't remember!  But I get the
feeling "bas" is not very "mod".


Mon, 10 Jan 2005 09:15:52 GMT  
 Reducing Load on CPU in Access - Sleep API?


Quote:

> Paste the code below in an empty module and you should be okay.

It seems harmless enough.


Mon, 10 Jan 2005 09:17:44 GMT  
 Reducing Load on CPU in Access - Sleep API?


Quote:
> Where have you pasted this code?
> Try creating a new module (Modules tab of Database window), and pasting
the
> whole thing in there. Generally the "Private Declare Sub" would go above
> any other procedures, at the top of the module with the "Option" lines.
> Save the module with a different name--say "basSleep".

> The DoEvents causes Access to yield processing power. If there is nothing
> else wanting that processing power, Windows will return the CPU to Access,
> and so the loop will appear to use 100%. If you start another
CPU-intensive
> process while that loop is running, you should see the percentage used by
> Access fall dramatically.

> The API call is really only needed if you want fine control over the
length
> of the delay. If you're happy with a delay that could be up to a second
> out, you could create your own loop in Access like this:

> Function Delay(Seconds As Long)
>     Dim dtNow As Date

>     dtNow = Now()
>     Do While DateDiff("s", dtNow, Now()) < Seconds
>         DoEvents
>     Loop
> End Function

Thanks my mistake was pasting it at the bottom of an existing module rather
into a brand new module.

It's made quite a bit of difference taking CPU load from 100% to around 22%
and even more with larger a time delay



Mon, 10 Jan 2005 09:15:39 GMT  
 Reducing Load on CPU in Access - Sleep API?
Don P. Mellon wrote

  > >  > > Save the module with a different name--say "basSleep".

  > >  > bahSleep?

  > > Sure, like the TV program, remember
  > > it, "bah, bah, blacksleep".

 > This "bas" stuff reminds me of something from
 > a long time ago.  Some sort of text editor I once
 > used.  God.  I just can't remember!  But I get the
 > feeling "bas" is not very "mod".

The basIlica where Mikey painted the pictures on the ceiling (and his Papa
didn't even punish him for it)? That'd be pretty old, not at all "mod",
wouldn't it?

I did work on a couple of projects where the established naming convention
was "mod" and "mdl" rather than "bas". But, I really like "bah" -- you can
identify the object and express an opinion with the same prefix.



Mon, 10 Jan 2005 11:20:26 GMT  
 Reducing Load on CPU in Access - Sleep API?
If I ever do any work in .NET and if the code is stored in modules, I think
"bah" would be my _preferred_ prefix.

--
Larry Linson
   http://www.ntpcug.org -- North Texas PC User Group
   http://members.tripod.com/ntaccess -- Access SIG
   http://members.tripod.com/accdevel -- Access Samples and Examples


Quote:
> Don P. Mellon wrote

>   > >  > > Save the module with a different name--say "basSleep".

>   > >  > bahSleep?

>   > > Sure, like the TV program, remember
>   > > it, "bah, bah, blacksleep".

>  > This "bas" stuff reminds me of something from
>  > a long time ago.  Some sort of text editor I once
>  > used.  God.  I just can't remember!  But I get the
>  > feeling "bas" is not very "mod".

> The basIlica where Mikey painted the pictures on the ceiling (and his Papa
> didn't even punish him for it)? That'd be pretty old, not at all "mod",
> wouldn't it?

> I did work on a couple of projects where the established naming convention
> was "mod" and "mdl" rather than "bas". But, I really like "bah" -- you can
> identify the object and express an opinion with the same prefix.



Mon, 10 Jan 2005 12:06:06 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Sleep API is using up 60% CPU time in the DLL

2. Reduce maximum CPU-Usage

3. VB Sleep Hangs up CPU

4. VB Sleep is causing the CPU to Hang!

5. HOW to wait or sleep to free CPU time

6. wscript.sleep uses 100% CPU

7. sleep api spawns other access processes

8. CPU load on exit

9. How to avoid 100% CPU-load

10. How to avoid 100% CPU-load

11. How do you determine CPU Load under Win98?

12. CPU load

 

 
Powered by phpBB® Forum Software