Thread?!
-
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?
-
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?
How u created the thread. Is it CreateThread API ?
rgds aneesh
-
How u created the thread. Is it CreateThread API ?
rgds aneesh
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
-
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?
-
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?
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
-
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?
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