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. Thread?!

Thread?!

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
6 Posts 5 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.
  • T Offline
    T Offline
    tanarnelinistit
    wrote on last edited by
    #1

    I've posted a question about my aplication blocking because it reads the com continuesly and I got the answer of using threads. But reading about it i found out that: "The thread remains active as long as the thread's function is executing" so I don't see how that helps. My thread will remain active forever because i'm using a function wich has a while loop to listen to the com port, a while loop which never ends. I want to be able to acces the menu of my aplication so I can put a menu comand like stop listening. Am I wrong or isn't a worker thread the answer for me?

    A H S D 4 Replies Last reply
    0
    • T tanarnelinistit

      I've posted a question about my aplication blocking because it reads the com continuesly and I got the answer of using threads. But reading about it i found out that: "The thread remains active as long as the thread's function is executing" so I don't see how that helps. My thread will remain active forever because i'm using a function wich has a while loop to listen to the com port, a while loop which never ends. I want to be able to acces the menu of my aplication so I can put a menu comand like stop listening. Am I wrong or isn't a worker thread the answer for me?

      A Offline
      A Offline
      Aneesh Valeri
      wrote on last edited by
      #2

      How u created the thread. Is it CreateThread API ?

      rgds aneesh

      T 1 Reply Last reply
      0
      • A Aneesh Valeri

        How u created the thread. Is it CreateThread API ?

        rgds aneesh

        T Offline
        T Offline
        tanarnelinistit
        wrote on last edited by
        #3

        I use AfxBeginThread. Shouldn't I use a separate process that deals with the reading of the COM? -- modified at 3:15 Wednesday 26th July, 2006

        1 Reply Last reply
        0
        • T tanarnelinistit

          I've posted a question about my aplication blocking because it reads the com continuesly and I got the answer of using threads. But reading about it i found out that: "The thread remains active as long as the thread's function is executing" so I don't see how that helps. My thread will remain active forever because i'm using a function wich has a while loop to listen to the com port, a while loop which never ends. I want to be able to acces the menu of my aplication so I can put a menu comand like stop listening. Am I wrong or isn't a worker thread the answer for me?

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          See Here[^] maybe it is some helpful to you

          _**


          **_

          WhiteSky


          1 Reply Last reply
          0
          • T tanarnelinistit

            I've posted a question about my aplication blocking because it reads the com continuesly and I got the answer of using threads. But reading about it i found out that: "The thread remains active as long as the thread's function is executing" so I don't see how that helps. My thread will remain active forever because i'm using a function wich has a while loop to listen to the com port, a while loop which never ends. I want to be able to acces the menu of my aplication so I can put a menu comand like stop listening. Am I wrong or isn't a worker thread the answer for me?

            S Offline
            S Offline
            Steve S
            wrote on last edited by
            #5

            Typically, your thread will loop continuously, with checks to see if (a) the current read has timed out, in which case you continue, or (b) an event was trggered (See CreateEvent in the API docs), in which case the thread exits. That way, you can trigger the event in your main thread when you want to quit the app, and then wait in the main thread for the comms thread to exit. You can combine the two by using COMMS events and waiting until either a received character is available or the other event was triggered, and acting accordingly. P.J.Naughter has written some excellent classes, one of which deals with comms ports, so check that out in the MFC/C++ libraries section here on CP.

            Steve S Developer for hire

            1 Reply Last reply
            0
            • T tanarnelinistit

              I've posted a question about my aplication blocking because it reads the com continuesly and I got the answer of using threads. But reading about it i found out that: "The thread remains active as long as the thread's function is executing" so I don't see how that helps. My thread will remain active forever because i'm using a function wich has a while loop to listen to the com port, a while loop which never ends. I want to be able to acces the menu of my aplication so I can put a menu comand like stop listening. Am I wrong or isn't a worker thread the answer for me?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Did you read this article from your last COM-related post? It goes into detail on how threads can be used for reading (and writing). Now your main UI thread can remain responsive.


              "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

              "Judge not by the eye but by the heart." - Native American Proverb

              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