progressbars

  • Thread starter Thread starter Andrew Bullock
  • Start date Start date
A

Andrew Bullock

Hi,


I have a very processor intensive method, and I want to report its
progress. When i get it to update a progressbar, label, print to console
etc. it vastly slows the method down.

Is there a way to avoid this?

Thanks

Andrew
 
message | Hi,
|
|
| I have a very processor intensive method, and I want to report its
| progress. When i get it to update a progressbar, label, print to console
| etc. it vastly slows the method down.
|
| Is there a way to avoid this?
|
| Thanks
|
| Andrew

I suppose you run this on an auxiliary thread, right?, How often do you
update the progress bar?
It's quite normal that this has some impact on performance when it happens
too often.


Willy.
 
Willy said:
message | Hi,
|
|
| I have a very processor intensive method, and I want to report its
| progress. When i get it to update a progressbar, label, print to console
| etc. it vastly slows the method down.
|
| Is there a way to avoid this?
|
| Thanks
|
| Andrew

I suppose you run this on an auxiliary thread, right?, How often do you
update the progress bar?
It's quite normal that this has some impact on performance when it happens
too often.


Willy.

Hi, no I dont run it on an aux thread. Would doing this increase
performance wrt updating a prgbar?


Thanks

Andrew
 
message | Willy Denoyette [MVP] wrote:
| > message | > | Hi,
| > |
| > |
| > | I have a very processor intensive method, and I want to report its
| > | progress. When i get it to update a progressbar, label, print to
console
| > | etc. it vastly slows the method down.
| > |
| > | Is there a way to avoid this?
| > |
| > | Thanks
| > |
| > | Andrew
| >
| > I suppose you run this on an auxiliary thread, right?, How often do you
| > update the progress bar?
| > It's quite normal that this has some impact on performance when it
happens
| > too often.
| >
| >
| > Willy.
| >
| >
|
| Hi, no I dont run it on an aux thread. Would doing this increase
| performance wrt updating a prgbar?
|

No, it won't, but it keeps the UI responsive. Whenever you interrupt your
"processor bound" code path to update the UI it's gonna hurt your
performance, unless you run this on a multi-core or HT CPU.


Willy.
 
Willy said:
message | Willy Denoyette [MVP] wrote:
| > message | > | Hi,
| > |
| > |
| > | I have a very processor intensive method, and I want to report its
| > | progress. When i get it to update a progressbar, label, print to
console
| > | etc. it vastly slows the method down.
| > |
| > | Is there a way to avoid this?
| > |
| > | Thanks
| > |
| > | Andrew
| >
| > I suppose you run this on an auxiliary thread, right?, How often do you
| > update the progress bar?
| > It's quite normal that this has some impact on performance when it
happens
| > too often.
| >
| >
| > Willy.
| >
| >
|
| Hi, no I dont run it on an aux thread. Would doing this increase
| performance wrt updating a prgbar?
|

No, it won't, but it keeps the UI responsive. Whenever you interrupt your
"processor bound" code path to update the UI it's gonna hurt your
performance, unless you run this on a multi-core or HT CPU.


Willy.

Oh right, ok thanks!

How exactly would i go about doing this?


Here is my code:

myClass x = new myClass;
x.run();



Thanks

Andrew
 
Yes it slows down everything if you change progress bar too often - let's say
10000 times. Such a big number of steps usually means that most of the time
your progress bar is not moving on every step so you don't have to change it
so often anyway. Thus solution: change progress bar not on every step but on
every nth step where n = 100 or 1000 for example.
 
Andrew said:
I have a very processor intensive method, and I want to report its
progress. When i get it to update a progressbar, label, print to console
etc. it vastly slows the method down.

Is there a way to avoid this?

Hard to say without seeing your code. I'd guess that you're maybe doing
some kind of calculation or something that is slowing everything down,
but it's difficult to tell without knowing, for example, if your code is
executing a loop 1,000,000,000 times or something, in which case,
updating a progress bar on each iteration could affect performance greatly.

Maybe you could add a Timer object and update the progress when a "tick"
event is raised.

Again, it's too hard for me to tell you for sure without seeing the code.

Good luck and hope that helps,
 
Willy said:
message | Hi,
|
|
| I have a very processor intensive method, and I want to report its
| progress. When i get it to update a progressbar, label, print to console
| etc. it vastly slows the method down.
|
| Is there a way to avoid this?
|
| Thanks
|
| Andrew

I suppose you run this on an auxiliary thread, right?, How often do you
update the progress bar?

I hope I'm not going off topic here, but did you mean update the
progress bar in an auxiliary thread? I ask because I was once told that
it wasn't good to update the UI from any thread but the parent. Is that
not true?

Thank you,
 
| Willy Denoyette [MVP] wrote:
| > message | > | Hi,
| > |
| > |
| > | I have a very processor intensive method, and I want to report its
| > | progress. When i get it to update a progressbar, label, print to
console
| > | etc. it vastly slows the method down.
| > |
| > | Is there a way to avoid this?
| > |
| > | Thanks
| > |
| > | Andrew
| >
| > I suppose you run this on an auxiliary thread, right?, How often do you
| > update the progress bar?
|
| I hope I'm not going off topic here, but did you mean update the
| progress bar in an auxiliary thread? I ask because I was once told that
| it wasn't good to update the UI from any thread but the parent. Is that
| not true?
|
| Thank you,
|
| --
| Sean

Yes it's true that you should not "directly" update UI elements from non UI
threads, you need to marshal the call by using Control.Invoke or BeginInvoke
or a BackgroudWorker in V2 of the framework.

Willy.
 
Hi,


I have a very processor intensive method, and I want to report its
progress. When i get it to update a progressbar, label, print to console
etc. it vastly slows the method down.

Is there a way to avoid this?

Thanks

Andrew

If you are using .NET 2.0 you can set the ProgressBar Style property
to Marquee. When you set it that way the progress bar will display
blocks that continuously scrolled fro left to right until you
terminate the scrolling. This is a good way to indicate processing
when you don't know how may things you are processing.

I suspect it would help your speed issue also.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
Willy said:
| Willy Denoyette [MVP] wrote:
| > I suppose you run this on an auxiliary thread, right?, How often do you
| > update the progress bar?
|
| I hope I'm not going off topic here, but did you mean update the
| progress bar in an auxiliary thread? I ask because I was once told that
| it wasn't good to update the UI from any thread but the parent. Is that
| not true?
Yes it's true that you should not "directly" update UI elements from non UI
threads, you need to marshal the call by using Control.Invoke or BeginInvoke
or a BackgroudWorker in V2 of the framework.


Thank you for clearing that up,
 

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

Back
Top