DoEvents for wpf?

M

mp

I have a wpf form with progress bar
searching files and parsing text takes time so prog bar is supposed to show
activity
the lines to increment it don't error but the control isn't repainting till
the end
Help says Application.DoEvents();
when i put that in the code i get compile error:
'System.Windows.Application' does not contain a definition for 'DoEvents'
but the help is for Windows forms not wpf
is there an equivalent in wpf? or how do i make the prog bar refresh
(i find no refresh or update or paint methods)
or maybe i'm not incrementing it correcxtly
foreach (string FileName in
System.IO.Directory.GetFiles(FolderName,"*.lsp"))

{

if (progressBar1.Value != progressBar1.Maximum)

{ progressBar1.Value++;} //<--------- does this not increment .Value ... it
was just a guess on my part as i thought ++ meant add one but maybe it won't
work on a property like that?

// do i need to do progressBar1.Value = progressBar1.Value +1?

//i was surprised not to find an .Increment or similar property on progbar

else

{

progressBar1.Value = progressBar1.Minimum;


}

thanks
mark
 
P

Peter Duniho

I have a wpf form with progress bar
searching files and parsing text takes time so prog bar is supposed to
show
activity
the lines to increment it don't error but the control isn't repainting
till
the end
Help says Application.DoEvents();
when i put that in the code i get compile error:
'System.Windows.Application' does not contain a definition for
'DoEvents'
but the help is for Windows forms not wpf
is there an equivalent in wpf? or how do i make the prog bar refresh

The correct way to solve this problem is to run your lengthy operation in
a different thread.

No doubt there is an equivalent to Application.DoEvents() in WPF, but in
reality DoEvents() itself isn't actually an appropriate solution to the
problem anyway.

There are lots of ways to do the "different thread" implementation, but
BackgroundWorker is the de facto .NET standard for this sort of thing.
[...]
//i was surprised not to find an .Increment or similar property on
progbar

The WPF version of ProgressBar doesn't, as far as I know, allow any way to
update the progress state except to modify the Value property (the Forms
version does, but I guess that doesn't help you :) ).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top