Re: CWinThread and Memory Leaks.
From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 01/14/05
- Next message: Doug Harrison [MVP]: "Re: CWinThread and Memory Leaks."
- Previous message: Steve Russell: "memory leak with grandchild class"
- In reply to: jim_OLP: "Re: CWinThread and Memory Leaks."
- Next in thread: jim_OLP: "Re: CWinThread and Memory Leaks."
- Reply: jim_OLP: "Re: CWinThread and Memory Leaks."
- Reply: jim_OLP: "Re: CWinThread and Memory Leaks."
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 13 Jan 2005 20:56:23 -0600
jim_OLP wrote:
>Thanks for the reply, I appreciate your expertise and hope you can get
>me out of this deadlock.
>
>No inter-thread SendMessage whatsoever.
None that you've identified so far, anyway. :)
>This is all stuff I've done
>successfully in the past, at 6.0, and I can't seem to make it work
>now.
>
>My main thread creates a CWinThread-derrived class with AfxBeginThread.
>That thread creates a modeless dialog in InitInistance. Things are fine
>until the main thread enters a loop iinside a message handler (the
>reason for the progress thread. The loop has a generous Sleep() in it
>so it's not hogging the CPU.
Inside the Sleep, it's also not processing messages or doing much of
anything else. This is anathema to UI threads, which as much as possible,
should sit in a GetMessage loop at all times.
>After that, the modeless dialog in the
>'progress' thread is dead. Spy++ shows it never gets any messages. If I
>break into the debugger I see my progress thread blocked at a
>DefWndProc call to m_pfnSuper. And it's total fog to me after that
>point, as I don't know what m_pfnSuper represents. I suspect MFC is
>trying to pass unhandled messages to the main window, thinking it's the
>parent of my dialog, but that makes no real sense. When I create the
>modeless dialog I don't give it a parent.
I'm sure you could get to the bottom of this if you kept spelunking around,
but I'd move the time-consuming operation out of the UI thread and into a
worker thread, and I'd have the UI thread host the progress dialog for the
worker. The worker would then communicate with this window (or another
designated target window) mainly through a (smallish) user-defined
PostMessage interface. This approach is probably the closest you can get to
something that "just works".
This is a wild guess, and hopefully someone will correct me or expand on
this as appropriate, but ISTR that if you don't specify the main window for
a secondary UI thread, MFC sets it to the primary thread's main window. I
don't know if this could pose a problem, but if I were ever to create
multiple UI threads, I'd look into it.
-- Doug Harrison Microsoft MVP - Visual C++
- Next message: Doug Harrison [MVP]: "Re: CWinThread and Memory Leaks."
- Previous message: Steve Russell: "memory leak with grandchild class"
- In reply to: jim_OLP: "Re: CWinThread and Memory Leaks."
- Next in thread: jim_OLP: "Re: CWinThread and Memory Leaks."
- Reply: jim_OLP: "Re: CWinThread and Memory Leaks."
- Reply: jim_OLP: "Re: CWinThread and Memory Leaks."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|