Re: How do I wait until myVar == true

Tech-Archive recommends: Fix windows errors by optimizing your registry



>> Jeez people, I gave the guy a warning about using DoEvents()...

>Where, out of interest? I didn't spot a warning.

I said this:

--- Begin ---
Also, if you do call DoEvents() within your loop do additional
debugging/coding so you don't let the user do something they should not be
doing while you are waiting for the processing to finish, such as pressing a
button again (start the process again for example), close the application,
etc...
--- End ---

>The trouble is that you spend 45 seconds writing it now - and then
>hours later, trying to debug a recursion problem.

I guess the point did not get across that this is for stuff that end users
will not see. If there is a chance for recursion just disable the button as
part of the click event handler, for example. If the button is disabled,
prevent closing the app via the OnClosing handler of the app. Do proper
exception handling to avoid locking the user into the application. Little
things like that.

> If the user won't
>care about it not being responsive, don't put the call to DoEvents() in
>at all. It'll look terrible, but at least you won't have a nasty
>threading issue to debug.

Maybe we do different kinds of projects... I do a lot of database work, and
some import routines will handle as many as 10 million records. I cannot
afford to no update the screen (ie, "processing 2,304 / 10,000") on very
long processes. These are processes one person does every three months for
example, so there is no huge need to make a beautiful interface. Data
integrity is the only concern, do as long as the transactions are handled
correctly no one cares about anything else.

>Delivery time is a priority for me, too. If I'm spending ages
>maintaining a previous rushed version which had horrible threading
>issues, I can't spend as much time developing new features.

The right solution for the right problem is always what should be done. The
OP stated it was some sort of import routine, similar to the kind of stuff I
write sometimes. No, I do not spend hours debugging these routines,
specially not because of threading issues.

>Hacking together poorly designed code never helps in the long run.
>[...]
>It's a case of trying to do the Right Thing.

Agreed, as long as we can also agree that the problem at hand, the user
audience, and the tolerance for different kinds of faults varies depending
on the problem at hand. I would not have advocated single-threaded
operation for something like spell check as you type, for example.


.


Quantcast