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. multi-thread question, perhaps

multi-thread question, perhaps

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorialannouncement
9 Posts 2 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.
  • G Offline
    G Offline
    goodoljosh1980
    wrote on last edited by
    #1

    I am writing a program where I want a sound file to play while I update the main window. I have everything implemented with the sndPlaySound() function, but when the program runs, it becomes unresponsive as long as the sound clip is running. That is, if the user tries to move the window, the whole thing goes white until the function that is updating the window is finished as well as the sound has stopped playing. I implemented a second thread to try to do nothing but call the sndPlaySound function, but that did not work either. It played the sound, but the window still goes unresponsive if anything interrupts in my functions. Does anyone have ideas on how to do this properly? I have searched through the multi-threaded posts, but haven't found anything so far. Please help, if possible. Or point me in another direction on how to implement this properly. Thanks.:confused:

    J 1 Reply Last reply
    0
    • G goodoljosh1980

      I am writing a program where I want a sound file to play while I update the main window. I have everything implemented with the sndPlaySound() function, but when the program runs, it becomes unresponsive as long as the sound clip is running. That is, if the user tries to move the window, the whole thing goes white until the function that is updating the window is finished as well as the sound has stopped playing. I implemented a second thread to try to do nothing but call the sndPlaySound function, but that did not work either. It played the sound, but the window still goes unresponsive if anything interrupts in my functions. Does anyone have ideas on how to do this properly? I have searched through the multi-threaded posts, but haven't found anything so far. Please help, if possible. Or point me in another direction on how to implement this properly. Thanks.:confused:

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      You can use the SND_ASYNC flag...  Look up the documentation for the PlaySound(...) function.    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      G 1 Reply Last reply
      0
      • J James R Twine

        You can use the SND_ASYNC flag...  Look up the documentation for the PlaySound(...) function.    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        G Offline
        G Offline
        goodoljosh1980
        wrote on last edited by
        #3

        I am already using the SND_ASYNC flag on sndPlaySound function. It seems that the drawing of the window doesn't happen once the user clicks anything in the window.

        J 1 Reply Last reply
        0
        • G goodoljosh1980

          I am already using the SND_ASYNC flag on sndPlaySound function. It seems that the drawing of the window doesn't happen once the user clicks anything in the window.

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          Are you using any other flags?  You might not be combining them correctly.  I have used the SND_ASYNC flag lots of time and never had it stall anything like you are describing.    You do not have any code that is waiting for the sound to finish, do you?    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          G 1 Reply Last reply
          0
          • J James R Twine

            Are you using any other flags?  You might not be combining them correctly.  I have used the SND_ASYNC flag lots of time and never had it stall anything like you are describing.    You do not have any code that is waiting for the sound to finish, do you?    Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

            G Offline
            G Offline
            goodoljosh1980
            wrote on last edited by
            #5

            No, I am not using any other flags in the sndPlaySound function. That seems to be working. What i am having a problem with (now that I look at it further), is in my ability to update the window as I need to. I am using a simple 'wait until X amount of time has passed', then I update some values, call Invalidate(); followed by a UpdateWindow(). This all works unless, in the middle of my function where I am drawing the window, the user clicks my window. Then, it doesn't update until the very end of the function and I am not sure why. I originally thought that maybe having the sound play on another thread would help, but it isn't.

            J 1 Reply Last reply
            0
            • G goodoljosh1980

              No, I am not using any other flags in the sndPlaySound function. That seems to be working. What i am having a problem with (now that I look at it further), is in my ability to update the window as I need to. I am using a simple 'wait until X amount of time has passed', then I update some values, call Invalidate(); followed by a UpdateWindow(). This all works unless, in the middle of my function where I am drawing the window, the user clicks my window. Then, it doesn't update until the very end of the function and I am not sure why. I originally thought that maybe having the sound play on another thread would help, but it isn't.

              J Offline
              J Offline
              James R Twine
              wrote on last edited by
              #6

              If your "wait until X amount of time has passed" implementation is a blocking one, like calling Sleep(...) or going into a spin, you will not be able to pump any messages, so you will not get the Paint message to update the screen.    For example, if you are trying to do some cheap animation using old-school-style techniques in a loop, it will not work the same under Windows.    If you are doing the above, you can change your wait to use a Timer message, and then when the timer message fires, you can do your updates.    Peace!

              -=- James
              Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              See DeleteFXPFiles

              G 1 Reply Last reply
              0
              • J James R Twine

                If your "wait until X amount of time has passed" implementation is a blocking one, like calling Sleep(...) or going into a spin, you will not be able to pump any messages, so you will not get the Paint message to update the screen.    For example, if you are trying to do some cheap animation using old-school-style techniques in a loop, it will not work the same under Windows.    If you are doing the above, you can change your wait to use a Timer message, and then when the timer message fires, you can do your updates.    Peace!

                -=- James
                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                See DeleteFXPFiles

                G Offline
                G Offline
                goodoljosh1980
                wrote on last edited by
                #7

                Thank you for the help. Can you point me in the direction of Timer message info? I have never heard of this before. Thanks again. Josh

                J 1 Reply Last reply
                0
                • G goodoljosh1980

                  Thank you for the help. Can you point me in the direction of Timer message info? I have never heard of this before. Thanks again. Josh

                  J Offline
                  J Offline
                  James R Twine
                  wrote on last edited by
                  #8

                  Look up the WM_TIMER message and the SetTimer(...) function.  If you need high-accuracy timers, look up multimedia timers.    Peace!

                  -=- James
                  Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  See DeleteFXPFiles

                  G 1 Reply Last reply
                  0
                  • J James R Twine

                    Look up the WM_TIMER message and the SetTimer(...) function.  If you need high-accuracy timers, look up multimedia timers.    Peace!

                    -=- James
                    Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                    Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                    See DeleteFXPFiles

                    G Offline
                    G Offline
                    goodoljosh1980
                    wrote on last edited by
                    #9

                    That was it, thank you. I appreciate the help.:)

                    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