Click here to Skip to main content
15,916,693 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 6:16
Zayax21-Aug-02 6:16 
GeneralRe: CString Problerm Pin
-Dy21-Aug-02 6:23
-Dy21-Aug-02 6:23 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 6:46
Zayax21-Aug-02 6:46 
GeneralRe: CString Problerm Pin
lucy21-Aug-02 6:51
lucy21-Aug-02 6:51 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 7:08
Zayax21-Aug-02 7:08 
GeneralRe: CString Problerm Pin
lucy21-Aug-02 7:16
lucy21-Aug-02 7:16 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 7:28
Zayax21-Aug-02 7:28 
GeneralRe: CString Problerm Pin
lucy21-Aug-02 7:36
lucy21-Aug-02 7:36 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 7:43
Zayax21-Aug-02 7:43 
GeneralRe: CString Problerm Pin
lucy21-Aug-02 7:42
lucy21-Aug-02 7:42 
GeneralRe: CString Problerm Pin
Zayax21-Aug-02 7:53
Zayax21-Aug-02 7:53 
GeneralRe: CString Problerm Pin
PJ Arends21-Aug-02 8:18
professionalPJ Arends21-Aug-02 8:18 
GeneralRe: CString Problerm Pin
Shay Harel21-Aug-02 6:12
Shay Harel21-Aug-02 6:12 
GeneralRe: CString Problerm Pin
Rashid Thadha21-Aug-02 6:14
Rashid Thadha21-Aug-02 6:14 
QuestionA Shading algorithm ? Pin
yarp21-Aug-02 6:01
yarp21-Aug-02 6:01 
AnswerRe: A Shading algorithm ? Pin
Chris Losinger21-Aug-02 7:13
professionalChris Losinger21-Aug-02 7:13 
GeneralRe: A Shading algorithm ? Pin
Stephane Rodriguez.21-Aug-02 7:27
Stephane Rodriguez.21-Aug-02 7:27 
GeneralRe: A Shading algorithm ? Pin
yarp21-Aug-02 21:54
yarp21-Aug-02 21:54 
GeneralChris Maudre Datagrid Pin
Mazdak21-Aug-02 5:35
Mazdak21-Aug-02 5:35 
GeneralRe: Chris Maudre Datagrid Pin
Chris Losinger21-Aug-02 5:36
professionalChris Losinger21-Aug-02 5:36 
GeneralRe: Chris Maudre Datagrid Pin
Mazdak21-Aug-02 7:29
Mazdak21-Aug-02 7:29 
Generalterminate a worker thread Pin
lucy21-Aug-02 5:31
lucy21-Aug-02 5:31 
I have a Dialog based MFC program, and in CMyDialogDlg::OnCreate I start my worker thread like this:
m_bThreadRun = TRUE;
HANDLE hThread = AfxBeginThread(MyWorkerThread, this);
if ( hThread == NULL )
    MessageBox("Cannot start worker thread.");


While in my worker thread, I check for the flag from parent:
UINT MyWorkerThread(LPVOID pParam)
{
    CMyDialogDlg * pDlg = (CMyDialogDlg *)pParam;
    while ( pDlg->m_bThreadRun)
    {
        // do something
    }
    TRACE("exit from the worker thread");
    return 0;
}


In order to terminate this worker thread, I did this:
CMyDialogDlg::OnClose()
{
   m_bThreadRun = FALSE;
   CDialog::OnClose();
}

But what troubles me is:
1. The trace line of my worker thread function "exit from the worker thread" was never printed.
2. When the program ended, this will appear in my Visual studio debug window:
etected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {54} client block at 0x017B4558, subtype 0, 112 bytes long.
a CWinThread object at $017B4558, 112 bytes long
Object dump complete.


what I am missing here? How can I terminate this worker thread gracefully?

Thanks a lot for your help!
GeneralRe: terminate a worker thread Pin
Tomasz Sowinski21-Aug-02 5:38
Tomasz Sowinski21-Aug-02 5:38 
GeneralRe: terminate a worker thread Pin
lucy21-Aug-02 6:01
lucy21-Aug-02 6:01 
GeneralRe: terminate a worker thread Pin
RChin21-Aug-02 23:43
RChin21-Aug-02 23:43 

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.