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 in Button Click

Sleep in Button Click

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
10 Posts 3 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.
  • V Offline
    V Offline
    varunpandeyengg
    wrote on last edited by
    #1

    In my MFC app, I needed to sleep (delay the thread) for 3 seconds. But when I added sleep in BtnClick afx function, it just didn't work. I did a work around be using 3 seconds Timmer. But How to avoid such situations in future??? Thanks for reply in advance :-) -- CHEERS!!!!

    _ 1 Reply Last reply
    0
    • V varunpandeyengg

      In my MFC app, I needed to sleep (delay the thread) for 3 seconds. But when I added sleep in BtnClick afx function, it just didn't work. I did a work around be using 3 seconds Timmer. But How to avoid such situations in future??? Thanks for reply in advance :-) -- CHEERS!!!!

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      How did you conclude that the sleep function does not work? Did you see any frozen UI for 3 seconds?

      You talk about Being HUMAN. I have it in my name AnsHUMAN

      V 1 Reply Last reply
      0
      • _ _AnsHUMAN_

        How did you conclude that the sleep function does not work? Did you see any frozen UI for 3 seconds?

        You talk about Being HUMAN. I have it in my name AnsHUMAN

        V Offline
        V Offline
        varunpandeyengg
        wrote on last edited by
        #3

        I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)

        _ A 2 Replies Last reply
        0
        • V varunpandeyengg

          I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          Are you using another thread to read/load the necessary files or the dll's or you are doing it in the main thread?

          You talk about Being HUMAN. I have it in my name AnsHUMAN

          V 1 Reply Last reply
          0
          • _ _AnsHUMAN_

            Are you using another thread to read/load the necessary files or the dll's or you are doing it in the main thread?

            You talk about Being HUMAN. I have it in my name AnsHUMAN

            V Offline
            V Offline
            varunpandeyengg
            wrote on last edited by
            #5

            I am loading it in the main thread itself...

            _ 1 Reply Last reply
            0
            • V varunpandeyengg

              I am loading it in the main thread itself...

              _ Offline
              _ Offline
              _AnsHUMAN_
              wrote on last edited by
              #6

              Then obviously your code for loading the dll's etc will not run during the freeze/sleep as the main thread is sleeping. You should load all dll's in a separate thread and once you are sure that they are loaded, notify the main thread to resume. May be you could have a better idea as well.

              You talk about Being HUMAN. I have it in my name AnsHUMAN

              A 1 Reply Last reply
              0
              • V varunpandeyengg

                I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)

                A Offline
                A Offline
                Albert Holguin
                wrote on last edited by
                #7

                UI frozen=Sleep worked... like it was suggested, create a loading thread and have that thread message back to the original thread when he's done. Using Sleep() in this manner is not acceptable, you're freezing the user interface on purpose, many do it on accident, but on purpose!?

                V 1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  Then obviously your code for loading the dll's etc will not run during the freeze/sleep as the main thread is sleeping. You should load all dll's in a separate thread and once you are sure that they are loaded, notify the main thread to resume. May be you could have a better idea as well.

                  You talk about Being HUMAN. I have it in my name AnsHUMAN

                  A Offline
                  A Offline
                  Albert Holguin
                  wrote on last edited by
                  #8

                  great feedback for OP :thumbsup:

                  1 Reply Last reply
                  0
                  • A Albert Holguin

                    UI frozen=Sleep worked... like it was suggested, create a loading thread and have that thread message back to the original thread when he's done. Using Sleep() in this manner is not acceptable, you're freezing the user interface on purpose, many do it on accident, but on purpose!?

                    V Offline
                    V Offline
                    varunpandeyengg
                    wrote on last edited by
                    #9

                    So does that means using Sleep() (in main thread) in mfc in condemned??? I never realized that. I think a lighter way was what I did (activated a timer and went to sleep there). Thread is also a good option. Thanks for the reply.

                    A 1 Reply Last reply
                    0
                    • V varunpandeyengg

                      So does that means using Sleep() (in main thread) in mfc in condemned??? I never realized that. I think a lighter way was what I did (activated a timer and went to sleep there). Thread is also a good option. Thanks for the reply.

                      A Offline
                      A Offline
                      Albert Holguin
                      wrote on last edited by
                      #10

                      It's condemned to use Sleep()(for this length of time) in UI thread(its common for people to separate the UI from the rest of the code).

                      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