>Simple - don't do that work on the UI thread, but instead fire up a
>worker thread - perhaps using BackgroundWorker or ThreadPool. The UI
[quoted text clipped - 3 lines]
>instead ask the UI thread for a little help, via Control.Invoke (sync)
>and Control.BeginInvoke (async)
Thanks, Marc. I was afraid you were going to say that. <g>
This particular stretch of code may take a lot of work to run it on
another thread. In other programs I've used Invoke for access to UI
threads, but this one won't go quietly.
In this case I'm triggering the CPU-hog process via a button. It
updates values that are polled by a dispatch loop on a
System.Forms.Timer (which runs in the UI thread). Some UI controls
DO update. Text in TextBoxes does not. Also Button events don't
propagate back.
Given that some of the controls do work, I was hoping that there was a
way to delegate enough CPU to get the others working too.
No other solution except another thread, eh?
Peter Duniho - 22 Jul 2007 18:29 GMT
> [...]
> In this case I'm triggering the CPU-hog process via a button. It
> updates values that are polled by a dispatch loop on a
> System.Forms.Timer (which runs in the UI thread). Some UI controls
> DO update. Text in TextBoxes does not.
Are you saying that you have multiple values being polled, some of which
are reflected in the form and some of which are not? That sounds like you
have a bug in either your value-polling code or the UI-updating code.
> Also Button events don't propagate back.
Propagate back from where to where? Why should button events (Click, I
assume you mean?) have to propagate at all? Should they not be handled in
the same thread that is already correctly polling values and updating the
UI?
> Given that some of the controls do work, I was hoping that there was a
> way to delegate enough CPU to get the others working too.
> No other solution except another thread, eh?
If your code isn't running, it's not because the thread is being starved.
Unless you are doing something evil like changing thread priority, it's
not possible for one thread in your process to completely prevent other
threads from getting CPU time.
You have a bug. Maybe more than one.
Pete