OnIdle () in a lie it? Or mfc of ----- bug -------?, You experts invited , and analyze

Category: VC/MFC -> Foundation Classes Author: hzljh Date: 2009-12-17 08:39:03
 
hzljh
2009-12-17 08:39:03
For some background processing , I created a user interface thread , would like to do some operations OnIdle () in , but found OnIdle () is only called once , it does not run in debugging .
debugging as follows :
int   CChildThread :: Run ()  
{
//   TODO:   Add   your   specialized   code   here   and / or   call   the   base   class
return   CWinThread :: Run ();                       // ---- ------------- (1)
}
int   CWinThread :: Run ()
{
ASSERT_VALID (this);
//   for   tracking   the   idle   time   state
BOOL   bIdle   =   TRUE;
LONG   lIdleCount   =   0;

//   acquire   and   dispatch   messages   until   a   WM_QUIT   message   is   received
for   (;;)
{
//   phase1:.   check   to   see   if   we   can   do   idle   work
while   (bIdle   & &!
:: PeekMessage (& m_msgCur,   NULL,   NULL,   NULL,   PM_NOREMOVE))
{
//   call   OnIdle   while   in   bIdle   state
if  ! (OnIdle (lIdleCount ++))                   // ------ (2)
bIdle   =   FALSE;   //   assume   " no   idle "   state
}

//   phase2:   pump   messages   while   available
do
{
//   pump   message,   but   quit   on   WM_QUIT
if   (! PumpMessage ())                             // ----- (3)
return   ExitInstance ();

//   reset   " no   idle "   state   after   pumping   " normal "   message
if   (IsIdleMessage (& m_msgCur))
{
bIdle   =   TRUE;
lIdleCount   =   0;
}

}   while   (:: PeekMessage (& m_msgCur,   NULL,   NULL,   NULL,   PM_NOREMOVE));
}

ASSERT (FALSE);     //   not   reachable
}
///////////////// ////////////////////////////////////////////////// //////////////////////////
BOOL   CWinThread :: PumpMessage ()
{
ASSERT_VALID (this );

if   (! :: GetMessage (& m_msgCur,   NULL,   NULL,   NULL)) // --------- (4)
{
# ifdef   _DEBUG
if   (afxTraceFlags   &   traceAppMsg)
TRACE0 (" CWinThread :: PumpMessage   -   Received   WM_QUIT \ n ". );
m_nDisablePumpCount ++;   //   application   must   die
//   Note:   prevents   calling   message   loop   things   in   'ExitInstance'
//   will   never   be   decremented
#endif
return   FALSE;
}

# ifdef   _DEBUG
if   (m_nDisablePumpCount & nbsp !; =   0)
{
TRACE0 (" Error:.   CWinThread :: PumpMessage   called   when   not   permitted \ n ");
ASSERT (FALSE) ;
}
#endif

# ifdef   _DEBUG
if   (afxTraceFlags   &   traceAppMsg)
_AfxTraceMsg (_T (" PumpMessage "),   & m_msgCur);
#endif

//   process   this   message

if   (m_msgCur.message  ! =   WM_KICKIDLE   & &  ! PreTranslateMessage (& m_msgCur))
{
:: TranslateMessage (& m_msgCur);
:: DispatchMessage (& m_msgCur);
}
return   TRUE;
}

Run ()     function by ( 1 ) entering the   in ( 2 ) is called once OnIdle      , then moves to ( 3 ) in ( 4 ) is blocked at . That is OnIdle () only run once
you master, analyze ! ! ! ! !
jss2760223330
2009-12-17 08:45:25
Idle is this mechanism , it is necessary
1, before a message is not : the mouse to move a message / paint / systimer news
2, thread message queue no news.
when excited , or have been calling GetMessage
solutions in do..while middle of a question before you in me over ,
Do you want me to just send the re-issue once ?