See below...
On 11 Feb 2007 11:42:46 -0800, "Dan24" <
dliberty@gmail.com>wrote:
Quote
On Feb 11, 9:09 pm, Joseph M. Newcomer <newco...@flounder.com>wrote:
>See below...
>On 11 Feb 2007 05:04:29 -0800, "Dan24" <dlibe...@gmail.com>wrote:
>
>
>
>
>
>>On Feb 11, 2:24 pm, David Wilkinson <no-re...@effisols.com>wrote:
>>>Dan24 wrote:
>>>>Hi,
>
>>>>I'm trying to create what seems to be a fairly simple thing to do - a
>>>>wait dialog in MFC.
>>>>To be more specific, I have a dialog which searches for files on the
>>>>hard drive and adds them to a listbox. Since searching is not done in
>>>>a worker / background thread, the main dialog (with the listbox) is
>>>>obviously not responding until the search is completed. Now all I want
>>>>to do is display a "Please wait" modal dialog while all this is
>>>>happening. I am aware of the fact I could use a worker thread for the
>>>>search, but I have no reason to allow interaction with the dialog
>>>>until the search is over. The best sollution I've come up with is
>>>>this:
>>>>1. Create a new thread
>>>>2. Call DialogBox() to display the wait dialog.
>>>>3. Change the cursor to busy (hourglass)
>>>>4. Post a WM_QUIT message to the thread when the search is done.
>
>>>>Is this the best solution or does MFC provide an easier way to achieve
>>>>this...?
>
>>>Dan:
>
>>>Not quite sure what you are saying here, but it sounds as if you are
>>>doing it backwards. Never show any GUI in the secondary thread -- just
>>>do the work there. And why WM_QUIT? The way I always use a worker thread
>>>that is performing a finite task is to have it post a custom mesage back
>>>to the main thread immediately before the worker thread function
>>>returns. The handler waits on the thread handle (which should signal
>>>immediately) so that it knows the thread has really ended, and then
>>>continues with the program.
>
>>>David Wilkinson- Hide quoted text -
>
>>>- Show quoted text -
>
>>David,
>
>>As I already mentioned - in this scenario doing things in a worker
>>thread is pointless. I do not need to enable interaction with the UI
>>while the search is in process therefore there is no reason to do the
>>search in a seperate thread (and then send the data between threads to
>>update the listbox).
>
>****
>You are making no sense. You say it is "pointless" because there is no interaction, and
>the first thing you do is try to create something that has user interaction, and then
>complain when the interaction doesn't work. Either you want an active GUI (if even to
>display a "waiting" dialog) or you don't. If you do, that says "worker thread". If you
>don't, then don't do anything that requires interaction, such as displaying a dialog
>saying there is some active computation. You can't have it both ways; you are saying you
>don't want a thread, and then you create a thread! Why? So you can have an interaction
>with your user? Exactly what part of "I really want an interaction with my users" did I
>fail to understand here?
>joe
>
>Joseph M. Newcomer [MVP]
>email: newco...@flounder.com
>Web:www.flounder.com">www.flounder.com
>MVP Tips:www.flounder.com/mvp_tips.htm-">www.flounder.com/mvp_tips.htm- Hide quoted text -
>
>- Show quoted text -
If you call a dialog that says "Please wait" and repaints itself
interaction, than yes - I want interaction.
****
Yes. This is interaction
*****
Quote
But I still think it's overkill to have a worker thread and transfer
data between threads when in fact there will be no user interaction
(responding to keyboard / mouse events) until the worker thread is
done anyway.
****
And it is not overkill to have a UI thread that puts you at all kinds of risks? What part
of "threads that contain GUI elements are dangerous"...something everyone has told you,
repeatedly, in this thread, are you missing?
I repeat: you are solving the problem in the wrong way. Do the work in the worker thread.
Use the GUI thread for interaction.
*****
Quote
Even if you are correct, I don't like your attitude - this is a
newsgroup, not your private cigar club.
*****
But when someone persists in saying "I want the experts to answer my problem" and then,
when all the experts tell you "don't do that" you insist that we are all wrong and you
want to do the opposite of what we are telling you, we being to think you are being overly
dense.
****
Quote
People are free to conduct
discussions and ask questions without being insulted. I've been using
MFC for over 6 years and yes, I've always used worker threads since
they were indeed the best solution (and it just might be in this case
as well). As I mentioned in my first post in this thread, I am aware
of the worker thread solution. Worker threads are useful in the
scenario when you need the UI to continue to be responsive to user
commands such as canelling the operation or allowing the user to
continue working with the application. I've clearly mentioned that
this is a different scenario and thus the worker thread seemed to be
an overkill at first thought.
****
And everyone has pointed out that you are missing the key ideas about GUI objects in
secondary threads. Repeatedly, we are telling you that this is the wrong approach. We
are telling you that none of us would *consider* a solution like yours, and that the thing
to do is to reorient your solution. You keep getting hung up on differences between "GUI
objects" and "interaction" as if there is a distinction...apparently you think that if the
user is not providing input, there is not an "interaction", and we are telling you the
opposite, and you keep saying "but my problem is different" and we keep saying "no it
isn't, do the work in a worker thread". So how many times do how many of us have to tell
you that your solution doesn't make sense, before we start figuring out that you are not
paying attention?
****
Quote
Thanks for your "help".
****
You asked a question. Many people gave you the answer. The fact that you don't like the
answer doesn't change the fact that your solution is one that is complex and risky, and in
fact you've already said it doesn't work. And your solution is one that we would not
consider for an instant. We keep telling you this. And you keep not getting it. At some
point, my patience runs out. As long as you keep insisting that an interaction is not an
interaction, that it makes sense to place user-visible GUI objects in the secondary thread
that have parents in the primary thread, and other solutions that don't make sense, people
are going to continue to tell you that your solution is wrong.
joe
*****
Joseph M. Newcomer [MVP]
email:
newcomer@flounder.com
Web:
www.flounder.com">
www.flounder.com
MVP Tips:
www.flounder.com/mvp_tips.htm">
www.flounder.com/mvp_tips.htm
-