win form update: which way is faster?

  • Thread starter Thread starter ~dr-sci-fi
  • Start date Start date
D

~dr-sci-fi

scenario:

i have a main form, and 4 custom controls that generates real-time wave
forms bitmaps (from h/w input signals);

i currently pass reference of one picturebox to each control (picturebox
controls are laid on main form), which runs on its own thread, and use
..BeginInvoke to update that picturebox,

the problem is: when all 4 controls are active, my CPU usage goes really
high to render the updated data.

i've noticed that is if i overlap my app window with some other app like
explorer, CPU usage goes normal, means it is only rendering that takes the
most of CPU time when app is visible.

please help me to optimize my application.

TIA

- sci
 
Hi, ~dr-sci-fi

usually such behavior means that you have not optimized painting procedure.
Ideally you should repaint only changed portions of the viewport on screen.
Correspondingly, you should call Update only for these parts of original
bitmap, which changed since previous paint.
It's a bit of headache, but you must use ClipRectangle in your
PaintEventArgs and intersect it with your updates.

As there is no code posted, it's difficult to say much more

HTH
Alex
 
thanks for reply

can u gimme some article link on how to optimize OnPaint to draw only updated parts on screen, as u said

thank

- sci
 
You can't because the entire screen updates in a moving graph, unless
I'm getting you wrong. If you need a moving graph that scrolls from say
left to right, then you do need to optimize which portion of the graph is
painted. However, in order to move the already drawn portion, you are
going to have to use a PInvoke call out to the GDI ScrollDC method.

If anyone has covered ScrollDC usage on this newsgroup, I haven't seen
it yet. All of the high perf Windows controls use it natively, such as the
ListBox and others that have scroll bars.
 
Back
Top