VB Sleep Method
Results 1 to 13 of 13

Thread: VB Sleep Method

  1. #1
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205

    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?

  2. #2
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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.

  3. #3
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205
    Sorry to sound foolish, but how do you call the Sleep API? I'm kinda new to this VB API thingee.

  4. #4
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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

    Code:
    sleep 60000
    Which will halt things for 60000 milliseconds, or 1 minute.

    Hope it works out for you

  5. #5
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205
    Great, thanks. I'm changing my program to include that now.

  6. #6
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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.

  7. #7
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205
    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?

  8. #8
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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.

  9. #9
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205
    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.

  10. #10
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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.

  11. #11
    Avatar Goes Here Radical Dreamer's Avatar
    Join Date
    Jan 2001
    Location
    Fairmont, West Virginia
    Posts
    4,866
    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.

  12. #12
    Registered User kingtbone's Avatar
    Join Date
    May 2001
    Location
    Freddy Beach
    Posts
    794
    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...

  13. #13
    Registered User Kymera's Avatar
    Join Date
    Feb 2001
    Location
    New York, NY USA
    Posts
    1,205
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •