OnIdle and UI thread  
Author Message
jkane





PostPosted: Tue Aug 09 09:33:58 CDT 2005 Top

MFC >> OnIdle and UI thread Hi,

I have an app that the Mainframe and the View are not in the same thread.
Then I find a problem, when the mouse is inside the View, the MainFrame's
OnUpdateUI handler is not call. Then I find it's because the main thread's
OnIdle is not called.

Why this happens and how to solved it?

Any comments are appreciated

Best

Jeff

Visual Studio23  
 
 
Ajay





PostPosted: Tue Aug 09 09:33:58 CDT 2005 Top

MFC >> OnIdle and UI thread Why do you have this scenario? On_UPDATE_COMMAND_UI is called
frequently whenever there is user action. Each time you would need to
switch thread context to the view and then back. This is prohibitively
expensive.

Most likely you have solved the problem incorrectly by creating view in
a separate thread.

-----------------
Ajay Kalra
EMail@HideDomain.com

 
 
Joseph





PostPosted: Tue Aug 09 18:01:55 CDT 2005 Top

MFC >> OnIdle and UI thread If you put the view in a separate thread, you are begging for problems. Why bother? There
is no good reason to put a view in a separate thread.

If there is some long computation the view must do, it can do THAT in a separate thread.
Keep the view in the main GUI thread. After you fix this problem, your other problems
will probably go away.
joe

On Tue, 9 Aug 2005 10:27:47 +0800, "jeff" <EMail@HideDomain.com> wrote:

>Hi,
>
>I have an app that the Mainframe and the View are not in the same thread.
>Then I find a problem, when the mouse is inside the View, the MainFrame's
>OnUpdateUI handler is not call. Then I find it's because the main thread's
>OnIdle is not called.
>
>Why this happens and how to solved it?
>
>Any comments are appreciated
>
>Best
>
>Jeff
>

Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 
 
jeff





PostPosted: Tue Aug 09 20:45:16 CDT 2005 Top

MFC >> OnIdle and UI thread The reason that I want to put the view in a thread is the view hosts a third
party Activex control which may perform long time operation. Doesn't it make
sense? or there is even better way to do it?

Thanks

Jeff

"Joseph M. Newcomer" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> If you put the view in a separate thread, you are begging for problems.
> Why bother? There
> is no good reason to put a view in a separate thread.
>
> If there is some long computation the view must do, it can do THAT in a
> separate thread.
> Keep the view in the main GUI thread. After you fix this problem, your
> other problems
> will probably go away.
> joe
>
> On Tue, 9 Aug 2005 10:27:47 +0800, "jeff" <EMail@HideDomain.com> wrote:
>
>>Hi,
>>
>>I have an app that the Mainframe and the View are not in the same thread.
>>Then I find a problem, when the mouse is inside the View, the MainFrame's
>>OnUpdateUI handler is not call. Then I find it's because the main thread's
>>OnIdle is not called.
>>
>>Why this happens and how to solved it?
>>
>>Any comments are appreciated
>>
>>Best
>>
>>Jeff
>>
>
> Joseph M. Newcomer [MVP]
> email: EMail@HideDomain.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


 
 
Ajay





PostPosted: Tue Aug 09 21:07:24 CDT 2005 Top

MFC >> OnIdle and UI thread In this case, the control should decide to launch a separate thread.
You shouldnt mess around with it.

----------
Ajay Kalra
EMail@HideDomain.com

 
 
jeff





PostPosted: Wed Aug 10 00:46:02 CDT 2005 Top

MFC >> OnIdle and UI thread Is it the same? The control's UI part covers my view window. The same
problem, mainframe's OnIdle handler is not called when mouse pointer is
insider the control's UI (if it's in another thread).

Best

Jeff
"Ajay Kalra" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> In this case, the control should decide to launch a separate thread.
> You shouldnt mess around with it.
>
> ----------
> Ajay Kalra
> EMail@HideDomain.com
>


 
 
Joseph





PostPosted: Wed Aug 10 15:58:50 CDT 2005 Top

MFC >> OnIdle and UI thread If you create any window in thread B whose parent is in thread A (such as a view), you are
doomed. There is very little payback in trying to debug such a scenario, because it means
you are only debugging today's bug. Tomorrow's bug will be different. And there *will* be
a bug tomorrow, just a different one. You can play this game for many years.

If you have an ActiveX control that is so poorly done that it does long computations in
the GUI thread, you are basically hosed. There is no architecture that will solve this if
the ActiveX control has any visible manifestation, which you suggest it has.
joe
On Wed, 10 Aug 2005 13:46:02 +0800, "jeff" <EMail@HideDomain.com> wrote:

>Is it the same? The control's UI part covers my view window. The same
>problem, mainframe's OnIdle handler is not called when mouse pointer is
>insider the control's UI (if it's in another thread).
>
>Best
>
>Jeff
>"Ajay Kalra" <EMail@HideDomain.com> wrote in message
>news:EMail@HideDomain.com...
>> In this case, the control should decide to launch a separate thread.
>> You shouldnt mess around with it.
>>
>> ----------
>> Ajay Kalra
>> EMail@HideDomain.com
>>
>

Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 
 
jeff





PostPosted: Wed Aug 10 21:35:04 CDT 2005 Top

MFC >> OnIdle and UI thread There is an example of this kind of app. The new beta version of IE7. The
mainframe and webpage window are in different thread.

"Joseph M. Newcomer" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> If you create any window in thread B whose parent is in thread A (such as
> a view), you are
> doomed. There is very little payback in trying to debug such a scenario,
> because it means
> you are only debugging today's bug. Tomorrow's bug will be different. And
> there *will* be
> a bug tomorrow, just a different one. You can play this game for many
> years.
>
> If you have an ActiveX control that is so poorly done that it does long
> computations in
> the GUI thread, you are basically hosed. There is no architecture that
> will solve this if
> the ActiveX control has any visible manifestation, which you suggest it
> has.
> joe
> On Wed, 10 Aug 2005 13:46:02 +0800, "jeff" <EMail@HideDomain.com> wrote:
>
>>Is it the same? The control's UI part covers my view window. The same
>>problem, mainframe's OnIdle handler is not called when mouse pointer is
>>insider the control's UI (if it's in another thread).
>>
>>Best
>>
>>Jeff
>>"Ajay Kalra" <EMail@HideDomain.com> wrote in message
>>news:EMail@HideDomain.com...
>>> In this case, the control should decide to launch a separate thread.
>>> You shouldnt mess around with it.
>>>
>>> ----------
>>> Ajay Kalra
>>> EMail@HideDomain.com
>>>
>>
>
> Joseph M. Newcomer [MVP]
> email: EMail@HideDomain.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


 
 
Joseph





PostPosted: Thu Aug 11 09:41:59 CDT 2005 Top

MFC >> OnIdle and UI thread And have you tried using Spy++ to see the relationship of the windows? I don't have it,
but I'll guess that the sort of relationship of a doc/view architecture isn't there.
Probably implements menu items by cross-thread PostMessage, for example. And besides, it
is not document/view architecture, so anything it does is probably quite ad hoc tuned to
this problem, and would not generalize to doc/view architectures where there is extremely
tight coupling.
joe

On Thu, 11 Aug 2005 10:35:04 +0800, "jeff" <EMail@HideDomain.com> wrote:

>There is an example of this kind of app. The new beta version of IE7. The
>mainframe and webpage window are in different thread.
>
>"Joseph M. Newcomer" <EMail@HideDomain.com> wrote in message
>news:EMail@HideDomain.com...
>> If you create any window in thread B whose parent is in thread A (such as
>> a view), you are
>> doomed. There is very little payback in trying to debug such a scenario,
>> because it means
>> you are only debugging today's bug. Tomorrow's bug will be different. And
>> there *will* be
>> a bug tomorrow, just a different one. You can play this game for many
>> years.
>>
>> If you have an ActiveX control that is so poorly done that it does long
>> computations in
>> the GUI thread, you are basically hosed. There is no architecture that
>> will solve this if
>> the ActiveX control has any visible manifestation, which you suggest it
>> has.
>> joe
>> On Wed, 10 Aug 2005 13:46:02 +0800, "jeff" <EMail@HideDomain.com> wrote:
>>
>>>Is it the same? The control's UI part covers my view window. The same
>>>problem, mainframe's OnIdle handler is not called when mouse pointer is
>>>insider the control's UI (if it's in another thread).
>>>
>>>Best
>>>
>>>Jeff
>>>"Ajay Kalra" <EMail@HideDomain.com> wrote in message
>>>news:EMail@HideDomain.com...
>>>> In this case, the control should decide to launch a separate thread.
>>>> You shouldnt mess around with it.
>>>>
>>>> ----------
>>>> Ajay Kalra
>>>> EMail@HideDomain.com
>>>>
>>>
>>
>> Joseph M. Newcomer [MVP]
>> email: EMail@HideDomain.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>

Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
 
 
Joseph





PostPosted: Thu Aug 11 12:08:36 CDT 2005 Top

MFC >> OnIdle and UI thread I should point out that by being *extremely* careful, the cross-thread messaging problem
can be dealt with by creating structures of windows for which this is not possible.
However, MFC makes a single-thread assumption about the frame/doc/view architecture and
makes no pretensions about trying to be as careful as would be needed.
joe

On Thu, 11 Aug 2005 10:41:59 -0400, Joseph M. Newcomer <EMail@HideDomain.com> wrote:

>And have you tried using Spy++ to see the relationship of the windows? I don't have it,
>but I'll guess that the sort of relationship of a doc/view architecture isn't there.
>Probably implements menu items by cross-thread PostMessage, for example. And besides, it
>is not document/view architecture, so anything it does is probably quite ad hoc tuned to
>this problem, and would not generalize to doc/view architectures where there is extremely
>tight coupling.
> joe
>
>On Thu, 11 Aug 2005 10:35:04 +0800, "jeff" <EMail@HideDomain.com> wrote:
>
>>There is an example of this kind of app. The new beta version of IE7. The
>>mainframe and webpage window are in different thread.
>>
>>"Joseph M. Newcomer" <EMail@HideDomain.com> wrote in message
>>news:EMail@HideDomain.com...
>>> If you create any window in thread B whose parent is in thread A (such as
>>> a view), you are
>>> doomed. There is very little payback in trying to debug such a scenario,
>>> because it means
>>> you are only debugging today's bug. Tomorrow's bug will be different. And
>>> there *will* be
>>> a bug tomorrow, just a different one. You can play this game for many
>>> years.
>>>
>>> If you have an ActiveX control that is so poorly done that it does long
>>> computations in
>>> the GUI thread, you are basically hosed. There is no architecture that
>>> will solve this if
>>> the ActiveX control has any visible manifestation, which you suggest it
>>> has.
>>> joe
>>> On Wed, 10 Aug 2005 13:46:02 +0800, "jeff" <EMail@HideDomain.com> wrote:
>>>
>>>>Is it the same? The control's UI part covers my view window. The same
>>>>problem, mainframe's OnIdle handler is not called when mouse pointer is
>>>>insider the control's UI (if it's in another thread).
>>>>
>>>>Best
>>>>
>>>>Jeff
>>>>"Ajay Kalra" <EMail@HideDomain.com> wrote in message
>>>>news:EMail@HideDomain.com...
>>>>> In this case, the control should decide to launch a separate thread.
>>>>> You shouldnt mess around with it.
>>>>>
>>>>> ----------
>>>>> Ajay Kalra
>>>>> EMail@HideDomain.com
>>>>>
>>>>
>>>
>>> Joseph M. Newcomer [MVP]
>>> email: EMail@HideDomain.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>>
>
>Joseph M. Newcomer [MVP]
>email: EMail@HideDomain.com
>Web: http://www.flounder.com
>MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: EMail@HideDomain.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm