Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sleep Function

Sleep Function

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MsmVc

    Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.

    C Offline
    C Offline
    CPallini
    wrote on last edited by
    #2

    Yes, it is possible: just set the Sleep interval to 1 minute (or whatever appropriate) and iterate it 30 times, then, whenever you need to shorten the wait delay, decrease the iteration limit. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    G 1 Reply Last reply
    0
    • M MsmVc

      Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #3

      On the other hand, if you have to use a sleep of 30 minutes, it is likely that your design could be improved. For what reason do you need to sleep so long ?

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • C CPallini

        Yes, it is possible: just set the Sleep interval to 1 minute (or whatever appropriate) and iterate it 30 times, then, whenever you need to shorten the wait delay, decrease the iteration limit. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        G Offline
        G Offline
        GAJERA
        wrote on last edited by
        #4

        But if you give sleep 1 hour, then what happen? I think it is not possible or we need to interrupt hardware.

        C 1 Reply Last reply
        0
        • G GAJERA

          But if you give sleep 1 hour, then what happen? I think it is not possible or we need to interrupt hardware.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #5

          Well, you may use WaitForSingleObject instead. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          G 1 Reply Last reply
          0
          • C CPallini

            Well, you may use WaitForSingleObject instead. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            G Offline
            G Offline
            GAJERA
            wrote on last edited by
            #6

            OK,but How we stop sleep function? as we already put sleep for 1 hour.

            C 1 Reply Last reply
            0
            • M MsmVc

              Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.

              C Offline
              C Offline
              Chris Meech
              wrote on last edited by
              #7

              What you are looking for is a WakeUp function. Unfortunately it doesn't exist. Since your thread is effectively blocked on Sleep, you need to handle this differently. This article [^] may give you some idea of how to accomplish what you are looking for.

              Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

              1 Reply Last reply
              0
              • G GAJERA

                OK,but How we stop sleep function? as we already put sleep for 1 hour.

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #8

                You cannot stop it (well, without a hammer...). :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                G 1 Reply Last reply
                0
                • M MsmVc

                  Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #9

                  You say you want to sleep for 30 minutes but might at a later stage decide to alter the duration. This begs the following question: Who is doing the deciding? If you've called Sleep[^] with the full duration it obviously can't be the calling thread because it's sleeping. Some possible solutions are:

                  • Sleep for a shorter duration and periodically check on the same thread (do this in a loop).
                  • Use the WaitForSingleObject[^] function with the dwMilliseconds parameter set to 30 minutes and for the hHandle parameter use a synchronisation object signalled by another thread (to abort the sleep).

                  Steve

                  1 Reply Last reply
                  0
                  • M MsmVc

                    Hi all I have question about Sleep Function.If i use Sleep function and set sleep values 30mins. But After 10mins i want to change Sleep values like 1mins or 2min. Is it possible.Please advice me.

                    _ Offline
                    _ Offline
                    _Superman_
                    wrote on last edited by
                    #10

                    Depending on your requirement, you could probably use SleepEx.

                    «_Superman_»
                    I love work. It gives me something to do between weekends.

                    Microsoft MVP (Visual C++)

                    Polymorphism in C

                    1 Reply Last reply
                    0
                    • C CPallini

                      You cannot stop it (well, without a hammer...). :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      G Offline
                      G Offline
                      GAJERA
                      wrote on last edited by
                      #11

                      Thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups