|
-
July 31st, 2002, 10:19 AM
#1
Registered User
VB Sleep Method
Okay, quick question for you guys. I'm programming in VB6 and I need a way of sleeping the program that does not show CPU usage at 100%. I'm using the timer fuction now with DoEvents, but the task manager shows 100%. Kinda freaky. Is there another way to do this?
-
August 1st, 2002, 08:11 AM
#2
Registered User
I think the only way to do it is to call the Sleep API. It uses very very few resources. Your form won't redraw until the sleep period is over though, so it might not be exactly what you're looking for. It is the only way I know of to do it with no resources.
-
August 1st, 2002, 09:27 AM
#3
Registered User
Sorry to sound foolish, but how do you call the Sleep API? I'm kinda new to this VB API thingee.
-
August 1st, 2002, 09:44 AM
#4
Registered User
Hey you're right, I didn't put any code in there.
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Stick that at the top, in the declarations section.
Then, when you want to use it, simply call
Which will halt things for 60000 milliseconds, or 1 minute.
Hope it works out for you
-
August 1st, 2002, 10:45 AM
#5
Registered User
Great, thanks. I'm changing my program to include that now.
-
August 1st, 2002, 11:22 AM
#6
Registered User
Let me know if it works. If you're trying to put it in an object module or something, we might have to do some more work.
-
August 2nd, 2002, 10:00 AM
#7
Registered User
Okay, I played with the Sleep method you gave me, and it works great. No more 100% CPU usage, not it shows the program as not responding. You just can't win, but I like the method you showed me instead of the timer method.
I am putting it into a Module, what kinds of things should I watch out for?
-
August 2nd, 2002, 10:08 AM
#8
Registered User
As long as it's not in an object module, you won't have any problems. If you ever do want to put it in a object (i.e. a Form) you have to make your own function in the modules section, and then call it from the object. Nothing too hard, just annoying.
Hopefully the drawbacks of using sleep are outweighed by the non processor hogging.
-
August 2nd, 2002, 02:16 PM
#9
Registered User
Okay, great. Thanks so much for your expertise. My program is really shaping up, all I need to do is add in database connectivity and reporting and I'll be all set.
-
August 2nd, 2002, 02:18 PM
#10
Registered User
Originally posted by Kymera
Okay, great. Thanks so much for your expertise. My program is really shaping up, all I need to do is add in database connectivity and reporting and I'll be all set.
Any time. Good luck to you.
-
August 5th, 2002, 10:27 AM
#11
Avatar Goes Here
Originally posted by Kymera
Okay, great. Thanks so much for your expertise. My program is really shaping up, all I need to do is add in database connectivity and reporting and I'll be all set.
Hope you have an easier time with that than I did.
-
August 6th, 2002, 07:52 AM
#12
Registered User
Originally posted by Radical Dreamer
Hope you have an easier time with that than I did.
Not with the sleep method stuff right? I hope you're talking about database connectivity. Either way, maybe we can help...
-
August 6th, 2002, 09:45 AM
#13
Registered User
Originally posted by Radical Dreamer
Hope you have an easier time with that than I did.
Yeah, I was being a little sarcastic. I have no illusions about my programming prowess, and opening an ADO connection to a SQL database is not something that I could wrap my mind around easily. I've spent more time reading than programming recently.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks