> This seems like a dangerous way to do things.
It's not dangerous per se.
> Your program becomes reentrant at this point, so
> depending on what else is happening all sorts of
> things can go wrong.
That's true but it is nothing new. Window procedures are often reentered.
It's why, by the way, that I suggested that the OP might want to disable
some UI elements before spinning the loop. Further, the OP was looking for
the equivalent of VB's DoEvents(). That's what I sketched.
> If you want to pause execution, why don't you break your routine into two
> pieces, and set a timer for the amount of time you want to pause.
> Then in your timer handler, post a message back to your window to schedule
> the second half of the task.
The OP had the pause by Sleep()-ing. The reason he posted the question was
that he needed to process messages while waiting.
Regards,
Will
Frank - 16 Jan 2007 21:13 GMT
> It's not dangerous per se.
>
>> Your program becomes reentrant at this point, so
>> depending on what else is happening all sorts of
>> things can go wrong.
I know I can't expect people to spend much time giving tutorials in a NG but
I wonder if you can just give a brief explanation of what the above means.
What should I be looking for in my program that might make this approach
dangerous?
Thanks
Ben Voigt - 16 Jan 2007 21:56 GMT
>> It's not dangerous per se.
>>
[quoted text clipped - 8 lines]
> What should I be looking for in my program that might make this approach
> dangerous?
Reentrant:
void A() {
...
DoEvents(); // -> this might call A()
...
}
Trouble:
int i;
void B(array<T> j) {
for( i = 0; i < j.Length; i++ ) {
DoEvents(); // this might change i
j[i].ToString(); // which could cause an array index bounds
exception here
}
}
Frank - 16 Jan 2007 22:21 GMT
Thanks for the insight
>>> It's not dangerous per se.
>>>
[quoted text clipped - 27 lines]
> }
> }
William DePalo [MVP VC++] - 17 Jan 2007 04:26 GMT
> I know I can't expect people to spend much time giving tutorials in a NG
> but I wonder if you can just give a brief explanation of what the above
> means.
>
> What should I be looking for in my program that might make this approach
> dangerous?
You have to understand what your application is doing. :-)
Seriously, say for example, that you have an application with a menu which
has an item that causes a function to run. Say that it is in that function
where you intend to put the little "wait" snippet that I sketched. If you
did nothing else but insert that snippet, it would be possible for the user
to pull down the menu and click the menu item which would cause the function
to be called a second time before the first call returns.
That would be bad but it is not the end of the world. The simple fix in a
case like that would be to disable the menu item, run the function and then
reenable it.
It's not at all unusual in places where you find such secondary message
loops to find some disabling of UI widgets before the loop runs followed by
reenabling afterwards. Exactly what kind of fiddling you need to do depends
on exactly what your application does.
Regards,
Will
Frank - 17 Jan 2007 08:04 GMT
I my situation the user could not cause reentrant.
Thanks for the explanation
>> I know I can't expect people to spend much time giving tutorials in a NG
>> but I wonder if you can just give a brief explanation of what the above
[quoted text clipped - 23 lines]
> Regards,
> Will
A Wieser - 17 Jan 2007 08:24 GMT
|I my situation the user could not cause reentrant.
| Thanks for the explanation
Are you sure? Press ALT+F4 while in your delayed portion.
Anthony Wieser
Wieser Software Ltd
Frank - 17 Jan 2007 13:48 GMT
What is Alt+F4. Is this it?
ALT+F4 (Close the active item, or quit the active program)
Sure didn't close my program.
I tried it but I have to press the spacebar and then Alt+F4 within one tenth
of a second.
Once I did see something on the screen but am not sure what caused it.
Thanks
> |I my situation the user could not cause reentrant.
> | Thanks for the explanation
[quoted text clipped - 3 lines]
> Anthony Wieser
> Wieser Software Ltd
A Wieser - 18 Jan 2007 06:51 GMT
| > Are you sure? Press ALT+F4 while in your delayed portion.
| >
| > Anthony Wieser
| > Wieser Software Ltd
| What is Alt+F4. Is this it?
| ALT+F4 (Close the active item, or quit the active program)
[quoted text clipped - 5 lines]
|
| Once I did see something on the screen but am not sure what caused it.
My prediction was that your program would process the shutdown message
WM_CLOSE, and tidy up, then destroy the window
But unfortunately, when your routine finished waiting, it would find that
all of its objects had been destroyed by the shutdown.
I can't predict what circumstance prevented that, though.
Anthony Wieser
Wieser Software Ltd
Frank - 18 Jan 2007 16:05 GMT
thanks for taking time to help
>| > Are you sure? Press ALT+F4 while in your delayed portion.
> | >
[quoted text clipped - 21 lines]
> Anthony Wieser
> Wieser Software Ltd