Re: DoEvents() "Hangs"
- From: wfairl@xxxxxxxxx
- Date: 3 Aug 2006 14:01:21 -0700
Don't sleep on the UI thread. Ever. You're preventing the UI
thread from processing any messages for 1 second. Disable the main form
and its controls or launch another simple modal form to actually launch
the processing thread and display some sort of "I'm running" indicator
until it receives notification (not by polling, by callback) that the
thread has finished.
Your implementation is broken, not the framework. This is not meant
to be snarky, just straightforward.
cedmunds@xxxxxxx wrote:
Exactly, I am using the BackgroundWorker (see code snippets) above. In
essence, I am firing off the stored proc and then putting the GUI in a
loop that sleeps for a while, awakens, and updates itself and then goes
back to sleep. This continues until the stored proc returns.
But the trouble is that it (the SleepAndUpdate loop) stops working
after a while. When it first fires up, everything is great and then
after an indeterminate period of time the DoEvents() stops returning.
It is puzzling.
I hate to take the "easy" way out and point to the framework but that
is indeed what it seems like the trouble is.
All helpful thoughts and suggestions (not the snarky ones about "Do
people really still use DoEvents() (is it even valid in C#?).") are
appreciated.
wfairl@xxxxxxxxx wrote:
Then you need to just disable the GUI programmitically. Thread.Sleep()
on the UI thread is never correct. Look into using the BackgroundWorker
class for a simple and sound solution if you're using 2.0.
http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
.
- Follow-Ups:
- Re: DoEvents() "Hangs"
- From: Greg Young
- Re: DoEvents() "Hangs"
- From: cedmunds
- Re: DoEvents() "Hangs"
- References:
- DoEvents() "Hangs"
- From: cedmunds
- Re: DoEvents() "Hangs"
- From: Greg Young
- Re: DoEvents() "Hangs"
- From: cedmunds
- Re: DoEvents() "Hangs"
- From: wfairl
- Re: DoEvents() "Hangs"
- From: cedmunds
- DoEvents() "Hangs"
- Prev by Date: Re: Databind Error???
- Next by Date: Re: c# - windows form controlbox
- Previous by thread: Re: DoEvents() "Hangs"
- Next by thread: Re: DoEvents() "Hangs"
- Index(es):
Relevant Pages
|