Click here to Skip to main content
15,879,095 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Worker thread Pin
Cedric Moonen14-Apr-10 4:16
Cedric Moonen14-Apr-10 4:16 
GeneralRe: Worker thread Pin
Maximilien14-Apr-10 4:44
Maximilien14-Apr-10 4:44 
GeneralRe: Worker thread Pin
CPallini14-Apr-10 5:15
mveCPallini14-Apr-10 5:15 
GeneralRe: Worker thread Pin
Maximilien14-Apr-10 5:17
Maximilien14-Apr-10 5:17 
GeneralRe: Worker thread Pin
CPallini14-Apr-10 5:28
mveCPallini14-Apr-10 5:28 
JokeRe: Worker thread Pin
Code-o-mat14-Apr-10 5:55
Code-o-mat14-Apr-10 5:55 
AnswerRe: Worker thread Pin
KarstenK14-Apr-10 3:34
mveKarstenK14-Apr-10 3:34 
AnswerRe: Worker thread Pin
David Crow14-Apr-10 3:53
David Crow14-Apr-10 3:53 
msr_codeproject wrote:
Please tell me what is the best method for invoking the AfxBeginThread.


You call (i.e., invoke) it at the moment you are ready for a secondary thread to exist. Instead of polling the serial port for data, you could let it tell your process when something is ready to be read, like:

HANDLE hCom = CreateFile("\\\\.\\COM1", ...); // use FILE_FLAG_OVERLAPPED
...
AfxBeginThread(ReadThread, this);
...
UINT ReadThread( LPVOID p )
{
    OVERLAPPED ov = {0};
    ov.hEvent = CreateEvent();

    while (! bDone)
    {
        if (! ReadFile(hCom, ..., &ov))
        {
            if (WaitForSingleObject(ov.hEvent, INFINITE) == WAIT_OBJECT_0)
            {
                GetOverlappedResult(hCom, &ov, ...);
            }
        }
    }
}
This is very simplistic and I've omitted a lot of details, but hopefully you get the general idea.

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Man who follows car will be exhausted." - Confucius


AnswerRe: Worker thread Pin
ThatsAlok14-Apr-10 18:25
ThatsAlok14-Apr-10 18:25 
GeneralRe: Worker thread Pin
msr_codeproject14-Apr-10 19:39
msr_codeproject14-Apr-10 19:39 
GeneralRe: Worker thread Pin
David Crow15-Apr-10 3:22
David Crow15-Apr-10 3:22 
Questionthe question of "sizeof"! Pin
wbgxx14-Apr-10 3:09
wbgxx14-Apr-10 3:09 
AnswerRe: the question of "sizeof"! Pin
David Crow14-Apr-10 3:14
David Crow14-Apr-10 3:14 
AnswerRe: the question of "sizeof"! Pin
Chris Losinger14-Apr-10 3:16
professionalChris Losinger14-Apr-10 3:16 
AnswerRe: the question of "sizeof"! Pin
Stephen Hewitt14-Apr-10 3:16
Stephen Hewitt14-Apr-10 3:16 
AnswerRe: the question of "sizeof"! Pin
CPallini14-Apr-10 3:22
mveCPallini14-Apr-10 3:22 
GeneralRe: the question of "sizeof"! Pin
wbgxx14-Apr-10 3:28
wbgxx14-Apr-10 3:28 
AnswerRe: the question of "sizeof"! Pin
Stephen Hewitt14-Apr-10 4:25
Stephen Hewitt14-Apr-10 4:25 
QuestionRe: the question of "sizeof"! Pin
Chris Meech14-Apr-10 7:02
Chris Meech14-Apr-10 7:02 
AnswerRe: the question of "sizeof"! Pin
CPallini14-Apr-10 11:24
mveCPallini14-Apr-10 11:24 
AnswerRe: the question of "sizeof"! Pin
SpaceMonkey197014-Apr-10 7:59
SpaceMonkey197014-Apr-10 7:59 
GeneralRe: the question of "sizeof"! Pin
Stephen Hewitt14-Apr-10 13:48
Stephen Hewitt14-Apr-10 13:48 
QuestionAvoid "Data Exchange" validation Pin
Code-o-mat14-Apr-10 0:04
Code-o-mat14-Apr-10 0:04 
AnswerRe: Avoid "Data Exchange" validation Pin
Eugen Podsypalnikov14-Apr-10 0:21
Eugen Podsypalnikov14-Apr-10 0:21 
GeneralRe: Avoid "Data Exchange" validation Pin
Code-o-mat14-Apr-10 0:50
Code-o-mat14-Apr-10 0:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.