How can I make the control refresh faster?

I have a custom control in C #. I noticed that the call is Refresh

much slower than I would like (about 0.1ms) even when I have an empty RePaint

function. Basically, my application processes the grid and, one by one, updates every cell of the grid. This is a rather inefficient behavior by design; when it's on, I want to be able to really see what each step of processing has done, and each step only ends up modifying one cell. Toggling double buffering doesn't really matter.

Can anyone suggest any advice?

Currently, the best improvement I have come up with is replacing my call with a Refresh

call Refresh2

. The last function is an exact copy RePaint

, except for two lines added at the top Graphics g = Graphics.FromHwnd(this.Handle); g.Clear(BackColor);

and replaced e.Graphics

with g

. I am suspicious of this, but it cuts the drawing speed in half. Note that the control I am working with has no subcomponents, so things like validation don't have the same concern.

+1


a source to share


2 answers


Updating will slow things down too much as you were going through it, try to compress events, i.e. don't update when you get a new grid, but set a variable when you need to update it, and let the timer check that variable every 1 sec for example and update.



+2


a source


Is an automatic recurring event updated or in response to a user event?

In the first case, it must be asynchronous (on its own thread). If in response to a custom event, then this will also be true if the "update" is not critical for the event.



If the code updating the interface is too slow, make sure that it does the interface update (it should have data ready ... which is along the double buffering vein). If not, do some logging, find out what is taking too long.

If data is needed first, then some lag is expected. If this is not acceptable, you will need a caching mechanism. You can automatically update the cache asynchronously, or return what is cached, get fresh data and then call another update .. or something like that.

0


a source







All Articles