TCP and Thread problem
-
Hi ppl, I am writing a simple TCP chat app in MFC c++ (dialog based), using two threads - one for listening and acceping and another one is for receiving and sending. The problem actualy occurs when I close (click on OK or Cancel) while some thread is running. I get an assert or/and unhandled exception pointing to a my code or some code inside dbgheap.c (Ln 1974:
if (_BLOCK_TYPE(pHead->nBlockUse) >= 0 && _BLOCK_TYPE(pHead->nBlockUse) < _MAX_BLOCKS)
) I suspect something about threads that are still running, though I tried to end them with TerminateThread and ExitThread. Please help. -
Hi ppl, I am writing a simple TCP chat app in MFC c++ (dialog based), using two threads - one for listening and acceping and another one is for receiving and sending. The problem actualy occurs when I close (click on OK or Cancel) while some thread is running. I get an assert or/and unhandled exception pointing to a my code or some code inside dbgheap.c (Ln 1974:
if (_BLOCK_TYPE(pHead->nBlockUse) >= 0 && _BLOCK_TYPE(pHead->nBlockUse) < _MAX_BLOCKS)
) I suspect something about threads that are still running, though I tried to end them with TerminateThread and ExitThread. Please help.Don't use TerminateThread or ExitThread to stop your thread. Instead, use a flag to signal that the thread should stop:
while (bThreadActive)
{
// Continue to process the thread
}Then, when you want to stop this thread (through your main thread), set this variable to false and wait[^] for the thread to finish.
Cédric Moonen Software developer
Charting control -
Don't use TerminateThread or ExitThread to stop your thread. Instead, use a flag to signal that the thread should stop:
while (bThreadActive)
{
// Continue to process the thread
}Then, when you want to stop this thread (through your main thread), set this variable to false and wait[^] for the thread to finish.
Cédric Moonen Software developer
Charting controlA helluva idea... I'll try that one, 10x