Jump to content
Software FX Community

Immense CPU usage on updating values


Recommended Posts

 I have a winform with 8 radial gauges on it. When I load my form, I begin taking in data on a seperate worker thread, performing some engineering units conversion, and invoking it back on the GUI thread for updates. Every gauge is updated simultaneously with a single method performing a foreach loop:

    public void ChangeGaugeValue(RadialGauge[] pageList, double[] valList)     {       int counter = 0;       foreach(RadialGauge i in pageList)       {         i.MainIndicator.Value = valList[counter];         counter += 1;       }     } 

With the thread set at 100ms intervals, I was experiencing a LOT of CPU usage, eventually causing some of the gauges to not update at all (as the processor was maxing and didn't have enough cycles to update all the gauges before going back to the higher priority worker thread).

After doing some profiling with ANTS, I find that the majority of slowdown is actually in updating the Value property of the gauge.

Am I doing something wrong? It seems like it is trying to Invalidate each gauge individually, instead of allowing me to set the properties to the new values, and then Invalidating the form. Any recommendations? 

Link to comment
Share on other sites

Assuming this method (ChangeGaugeValue) is running on the UI thread, I don't see anything wrong.

Some Gauges are quite complex and are CPU intensive.

The invalidate does occur when you set the value. In some cases an animation runs to move the needle. This animation, however, is based on a Windows Timer so it also runs in the UI thread.

You can turn off animations by setting:

MainIndicator.AnimationSpan = new TimeSpan(0);




Link to comment
Share on other sites

I tried the fix that you recommend here, and didn't notice any real improvement.

When I first load up the form, it starts up the worker thread immediately. I notice something really interesting here, there are 8 gauges on the screen, 2 large ones in the center, 2 medium sized ones to the left and right of those, and then 4 smaller ones below those on either side. When I start up the form, only the four smaller gauges and the medium one on the right are painted. The other three gauges don't paint unless I actively drag the window around the screen.

The thing that's odd about this is that I have a pretty good system - 2ghz core 2 duo, 2 gigs of ram - and other controls paint fine. I can add more and more controls to the screen, but it's always those three that don't seem to paint properly. If I disable a few of the working gauges, then the "broken" ones will paint.

Any idea what is going on here? 

Link to comment
Share on other sites

I was getting the same "drag to update" problem (using the demo trial) in a tight loop.  I had to put in a couple of refreshes and a DoEvents to get it to paint.  I'm just experimenting, but my simple loop is:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



Do While True

Me.RadialGauge1.MainIndicator.Value = 100 * Rnd()







End Sub


It seems that if I take out either refresh or the DoEvents I get the sticky needle situation, even the form level refresh, oddly.

(VB 2005 Express on Vista)


Link to comment
Share on other sites

I uploaded a test solution here:


There's two configurable options at the top to show you this problem:

int timeDelay, and bool useTimer.  The problem I am having uses threads. One alternative is to use a timer, but timers bog down and don't gaurantee any kind of prompt execution, although I added that option to show you the comparison. The pariticular application I'm developing is central to a customer project and doesn't need to "play nice" with other applications on the system, as this will be the only major application running besides the OS. 

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...