tags:

views:

154

answers:

3

I'm making a desktop application in C# which contains a moving News Bar labels. I'm using a timer to move these labels but the problem is that when i make the interval of this timer low (1-10 for example) the application takes very high percentage of CPU Usage, And when i make it higher(200 -500 ) the movement of the labels becomes intermittent or not smooth movement even that the user may not be able to read the news in Comfortable way.

((More Information)) it is Windows form application. the way i move the labels is as follows : the news items from RSS feeds are represented in a group of linklabels. All these linklabels are added to a flowlayout container. The timer moves the whole flowlayout container. I found this way according to my knowledge the best way to making the news bar. If you have better idea or solution please help

A: 

What does the timer interval represent? If it's milliseconds, then you can divide the number of updates per second that you want into one thousand and get the timer rate.

You could also use Sleep(100) or so, but it may just be that you're trying to do too much in your update. Maybe you can do "important changes" much less frequently, like only every 100 updates or so, or put those on their own timer, and do as little as possible to update the scrolling much more frequently.

It's not surprising that your application takes a lot of CPU when you have it set to do its update 100 or 1000 times per second. :)

dash-tom-bang
the timer just moves the flowlayoutpanel ((Please see Information added above))
EgyEast
A: 

I suspect the problem is that you're using the timer to move the ticker as well as populate the data?

If you want to use a timer to scroll the view, that should be fine. Your code needs to be extremely light (just update the vertical or horizontal positions and return). A better approach, however, would be to use something like a "game loop" to achieve whatever update frequency you're after (within each iteration, time how long it takes to move the view, then Sleep for the number of milliseconds remaining to hit your target frequency.)

Update the data from a separate timer/thread.

hemp
A: 

Ok, Thanks All. I've found where was the problem. The Background color of the flowlayoutpanel was set to be transparent. so every time the panel moves it checks the color behind the container to assign it to its background color. When it is set to false the problem disappears. Thanks all for your help

EgyEast