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. Wait for Thread

Wait for Thread

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 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.
  • R Offline
    R Offline
    RedDragon2k
    wrote on last edited by
    #1

    Hello, I currently working on a program. Suprise, suprise. And this program has to wait for a client to connect and then do something with the client. I put the wait for client, etc. stuff into a thread so that my interface is still useable, but since it's a thread my main program continues running. How can I prevent this ? So the Interface of my Main Program should keep useable but it should not continue work till a client connected. Any Ideas or Suggestions ? With best regards, Benedikt

    S N J 3 Replies Last reply
    0
    • R RedDragon2k

      Hello, I currently working on a program. Suprise, suprise. And this program has to wait for a client to connect and then do something with the client. I put the wait for client, etc. stuff into a thread so that my interface is still useable, but since it's a thread my main program continues running. How can I prevent this ? So the Interface of my Main Program should keep useable but it should not continue work till a client connected. Any Ideas or Suggestions ? With best regards, Benedikt

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

      RedDragon2k wrote:

      my main program continues running

      Wasn't that the whole idea of making another thread? I assume you mean you don't want the user to be able to use the UI? If this is the case just disable the main window or bring up a modal "please wait" dialog that is dismissed when the worker thread is done by sending a WM_CLOSE message to it. Steve

      R 1 Reply Last reply
      0
      • R RedDragon2k

        Hello, I currently working on a program. Suprise, suprise. And this program has to wait for a client to connect and then do something with the client. I put the wait for client, etc. stuff into a thread so that my interface is still useable, but since it's a thread my main program continues running. How can I prevent this ? So the Interface of my Main Program should keep useable but it should not continue work till a client connected. Any Ideas or Suggestions ? With best regards, Benedikt

        N Offline
        N Offline
        Nick_Kisialiou
        wrote on last edited by
        #3

        Can you use ::WaitForSingleObjectEx(...) function?

        S 1 Reply Last reply
        0
        • N Nick_Kisialiou

          Can you use ::WaitForSingleObjectEx(...) function?

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

          If he uses this API the UI will not redraw properly while the worker is running. Steve

          1 Reply Last reply
          0
          • R RedDragon2k

            Hello, I currently working on a program. Suprise, suprise. And this program has to wait for a client to connect and then do something with the client. I put the wait for client, etc. stuff into a thread so that my interface is still useable, but since it's a thread my main program continues running. How can I prevent this ? So the Interface of my Main Program should keep useable but it should not continue work till a client connected. Any Ideas or Suggestions ? With best regards, Benedikt

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            That is easy just do not return from the thread util a client has reacted. No wait a client may never react and then you end up with an infinite loop. There are multiple ways to provide a solution to this problem, the simpilest is to disable all commands that require the client to communicate with you. That is anything that is not be dependent on an outside source, like close application. The main thread should never be disabled, because you always need the option of shuting down the program. INTP “Testing can show the presence of errors, but not their absence.” Edsger Dijkstra

            1 Reply Last reply
            0
            • S Stephen Hewitt

              RedDragon2k wrote:

              my main program continues running

              Wasn't that the whole idea of making another thread? I assume you mean you don't want the user to be able to use the UI? If this is the case just disable the main window or bring up a modal "please wait" dialog that is dismissed when the worker thread is done by sending a WM_CLOSE message to it. Steve

              R Offline
              R Offline
              RedDragon2k
              wrote on last edited by
              #6

              Hello, nice ideas. But I think they won't work, because the my app does are done silent. All in all just want the UI to be drawn correctly. And the possibility to stop the work (so interaction). Hope this helps, Benedikt

              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