Thread: Alternative to Sleep function ?

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    6

    Alternative to Sleep function ?

    Whats the alternative to using windows' "Sleep" in the windows environment? Specifically, I'm trying create a delay when the player touches a switch (its a boolean switch/*on/off*/) so that the switch doesn't remain turned on at the time the collision is true.


  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    San Jose
    Posts
    2,633
    Why do you need an alternative ?

  3. #3

  4. #4
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    i need to apply this into my Digital image processing project which require dynamic gesture capturing from web camera. While using sleep function the video streaming stops for the time given as parameter. i only intend to skip the execution of one command and not stop entire program.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    131
    Quote Originally Posted by aswinkgopan View Post
    i only intend to skip the execution of one command and not stop entire program.
    Wouldn't that be better handled by a boolean conditional rather than an actual sleep function?

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Right, then rather than having the program wait at a particular point, you simply want to perioducally check how much time has passed, by comparing the current time against some previously remembered time. If it's greater by at least a certain amount, then it's time to do that other thing.
    The GetTickCount function is very useful for this.

    Other options are to have Windows work out when it's time to do that special thing for you, using a WM_TIMER message and the functions associated with that.

    Lastly, someone is bound to mention threading. However, without knowledge of how to do probably both of the above ways first, using threading (which is pretty much the hardest thing to get right in computer programming) would drive you completely insane before you got anything working 100%.
    Last edited by iMalc; 05-01-2012 at 01:08 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Apr 2012
    Posts
    6
    thank you for your support... that worked.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sleep function
    By pollypocket4eva in forum C Programming
    Replies: 11
    Last Post: 02-16-2009, 03:28 AM
  2. Alternative to sleep()
    By Abda92 in forum C Programming
    Replies: 4
    Last Post: 12-28-2007, 04:03 PM
  3. An alternative wait function?
    By Nanor in forum C++ Programming
    Replies: 11
    Last Post: 01-08-2007, 12:43 PM
  4. Using the sleep function
    By HyperHelix in forum C++ Programming
    Replies: 3
    Last Post: 04-30-2005, 09:18 AM
  5. The sleep function...
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2004, 03:19 PM