Re: Reading Serial Port
"clinisbut" <email@example.com> wrote in message
By the way, this question is about closing the thread when my app
closes, but what about shutting down my thread whenever I want? Should
I call AfxEndThread?
I created this way:
(MySerial*) pMySerial = (MySerial*)
AfxBeginThread( RUNTIME_CLASS( MySerial ), THREAD_PRIORITY_NORMAL, 0,
I'm really lost in this issue.
I don't know how you are shutting down your thread. You are creating a
message-driven thread, which would normally be commanded to shut down by
posting a message to it. But you are setting a shutdown event, which can
only be seen by a thread that is not waiting for messages. Is your thread
in a loop with a WaitFor... call? Or is it waiting for a message? Why did
you create a message-driven thread?
Whatever the answer is, you can shut down your thread at any time, the same
way you shut it down for program close. There is no reason for there to be
Forget about AfxEndThread. The way to terminate a message-driven thread is
to have the thread itself call PostQuitMessage. You do this in response to
receiving whatever message or event you are using to ask the thread to quit.
Scott McPhillips [VC++ MVP]