Re: Could Application.DoEvents(); messup code execution ??



Well, the Sleep isn't doing you any favors... you are on the same thread -
you are just slowing it down (assuming there isn't any other threading going
on).

DoEvents is notorious for causing re-entrancy issues exactly as you have
described. If you are doing background work, I would recommend a worker
thread, but this isn't convenient if you are talking to the UI lots (only
the UI thread can talk to the UI controls; the worker thread would have to
do lots of marshalling).

In this case, it sounds like the most pragmatic thing to do would be to add
a flag (either a bool or an int counter) to prevent re-entrancy:

bool inProgress;
void Some_Click(object sender, EventArgs args) {
if(inProgress) return; // dammit I heard you already! stop clicking!
inProgress = true;
try {
// your current code
} finally {
inProgress = false;
}
}

Marc


.


Loading