Problem Closing UI thread dialog boxes from main app 
Author Message
 Problem Closing UI thread dialog boxes from main app

Happy new year!
I have an application that create UI threads dialog boxes as steps
below.

1)
void CSysTab_EditorMainFrame::OnSearch()
{
        CFindThread* pFindThread = new CFindThread(m_hWnd); //thread
dies when wnd closes
        pFindThread->CreateThread();

Quote:
}

2)thread creates dialog
BOOL CFindThread::InitInstance()
{
        BOOL bReturn = m_wndSearchDlg.Create(IDD_SEARCH_DLG);
        m_wndSearchDlg.ShowWindow(SW_SHOW);
        m_pMainWnd = &m_wndSearchDlg;
        return TRUE;
Quote:
}

The problem:
if i close the main application and several dialogs are about the
threads do not die cleanly and at times the OS hangs!!!

I tried EnumChildWindows and sending WM_CLOSE (kills thread
automatically) to all child windows and their child windows but since
these dialogs are pop ups and not child windows it doesnt work.

Hope someone can figure this one out for me

Thnx in advance
Alon

Sent via Deja.com
http://www.*-*-*.com/



Fri, 20 Jun 2003 15:57:20 GMT  
 Problem Closing UI thread dialog boxes from main app

Quote:

> Happy new year!
> I have an application that create UI threads dialog boxes as steps
> below.

> 1)
> void CSysTab_EditorMainFrame::OnSearch()
> {
>         CFindThread* pFindThread = new CFindThread(m_hWnd); //thread
> dies when wnd closes
>         pFindThread->CreateThread();
> }
> 2)thread creates dialog
> BOOL CFindThread::InitInstance()
> {
>         BOOL bReturn = m_wndSearchDlg.Create(IDD_SEARCH_DLG);
>         m_wndSearchDlg.ShowWindow(SW_SHOW);
>         m_pMainWnd = &m_wndSearchDlg;
>         return TRUE;
> }
> The problem:
> if i close the main application and several dialogs are about the
> threads do not die cleanly and at times the OS hangs!!!

> I tried EnumChildWindows and sending WM_CLOSE (kills thread
> automatically) to all child windows and their child windows but since
> these dialogs are pop ups and not child windows it doesnt work.

> Hope someone can figure this one out for me

> Thnx in advance
> Alon

When your application is closing post a user-defined message (WM_APP+?) to each
thread that commands it to close.  Use PostMessage to threads that have a main
window or PostThreadMessage to windowless threads.  The thread can handle the
message with ON_MESSAGE or ON_THREAD_MESSAGE in its message map.  The main
thread should then wait until all secondary threads have closed (use
WaitForSingleObject or WaitForMultipleObjects) before continuing to shut down.

--
Scott McPhillips [VC++ MVP]



Sat, 21 Jun 2003 02:45:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

2. MFC UI Thread doesnt start when COM method called in multi-threaded MFC dialog App

3. MFC UI threads - application freezes when returning to main app

4. posting messages from UI thread to main app

5. Creating a dialog box in a UI-Thread

6. main app closes while dll module closes

7. Dialog-Based App and Main Dialog Problem

8. dialog can not be closed when I close sdi main window

9. Starting a UI Thread from a UI Thread.

10. Doubt in dialog based threads in linux (UI threading)

11. Closing App from Splitter Window Dialog Box

12. Doubt in dialog based threads in linux (UI threading)

 

 
Powered by phpBB® Forum Software