mihrlogic
asked on
How to force a WPF Control to Refresh mid-processing
Peace be with you all,
In trying to adapt to the new WPF model, I have not figured out how to update a
control in the midst of processing.
--------------
//non-complete example:
Button buGo;
TextBlock tbOutput;
private void buGo_Click( object sender, RoutedEventArgs e ) {
int i;
for (i=0; i < 1000; ++i) {
tbOutput.Text = i.ToString();
}
--------------
After clicking on buGo, the program runs and then tbOutput changes to '999'.
What I want is to see each individual number '0' ... '999' in tbOutput after
each modification, even if I have to make a fct call manually after setting
tbOutput.Text.
In System.Windows.Forms, I could call tbOutput.Refresh() which would
force the control to re-render itself immediately.
I am having no luck finding a corollary in the WPF and am guessing that
some sort of threading solution may be the only way to accomplish this,
meaning that I may have to split out my processing into a second thread,
which makes an 'Invoke'-ish type call back to the original thread that
created the controls.
Thanks in advance,
Robert McCall
PS: *MODERATORS* Might I suggest 3 new .NET sub-categories: WPF, WCF and WF/WWF?
Now that Microsoft has officially released .NET 3.0, these questions are gonna start flooding in, maybe.
In trying to adapt to the new WPF model, I have not figured out how to update a
control in the midst of processing.
--------------
//non-complete example:
Button buGo;
TextBlock tbOutput;
private void buGo_Click( object sender, RoutedEventArgs e ) {
int i;
for (i=0; i < 1000; ++i) {
tbOutput.Text = i.ToString();
}
--------------
After clicking on buGo, the program runs and then tbOutput changes to '999'.
What I want is to see each individual number '0' ... '999' in tbOutput after
each modification, even if I have to make a fct call manually after setting
tbOutput.Text.
In System.Windows.Forms, I could call tbOutput.Refresh() which would
force the control to re-render itself immediately.
I am having no luck finding a corollary in the WPF and am guessing that
some sort of threading solution may be the only way to accomplish this,
meaning that I may have to split out my processing into a second thread,
which makes an 'Invoke'-ish type call back to the original thread that
created the controls.
Thanks in advance,
Robert McCall
PS: *MODERATORS* Might I suggest 3 new .NET sub-categories: WPF, WCF and WF/WWF?
Now that Microsoft has officially released .NET 3.0, these questions are gonna start flooding in, maybe.
Does Application.DoEvents help?
ASKER
AlexFM,
No, there is no such call in the WPF ~ Windows Presentation Foundation. It's a completely
different model; and, FYI, Application.DoEvents() exposes your program to all kinds of problems
with re-entrancy, so it is better to use Obj.Refresh() instead.
Thanks anyway,
Robert
No, there is no such call in the WPF ~ Windows Presentation Foundation. It's a completely
different model; and, FYI, Application.DoEvents() exposes your program to all kinds of problems
with re-entrancy, so it is better to use Obj.Refresh() instead.
Thanks anyway,
Robert
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.