Re: Could Application.DoEvents(); messup code execution ??
- From: "Marc Gravell" <marc.gravell@xxxxxxxxx>
- Date: Thu, 20 Mar 2008 10:38:36 -0000
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
.
- Follow-Ups:
- Re: Could Application.DoEvents(); messup code execution ??
- From: Kristijan Marin
- Re: Could Application.DoEvents(); messup code execution ??
- References:
- Could Application.DoEvents(); messup code execution ??
- From: Kristijan Marin
- Could Application.DoEvents(); messup code execution ??
- Prev by Date: automtic closing
- Next by Date: Re: Could Application.DoEvents(); messup code execution ??
- Previous by thread: Could Application.DoEvents(); messup code execution ??
- Next by thread: Re: Could Application.DoEvents(); messup code execution ??
- Index(es):
Loading