Note that there are some explanatory texts on larger screens.

plurals
  1. POTimer problem with GDI+
    primarykey
    data
    text
    <p>I am currently stuck at a really strange problem with GDI and timers. </p> <p>First the Code:</p> <pre><code>class Graph : UserControl { private System.Threading.Timer timer; private int refreshRate = 25; //Hz (redrawings per second) private float offsetX = 0; //X offset for moving graph public Graph() { timer = new System.Threading.Timer(timerTick); } private void timerTick(object data) { offsetX -= 1 / refreshRate; this.Invalidate(); } public void timerStart() { timer.Change(0, 1000 / refreshRate); } private void onPaint(object sender, PaintEventArgs e) { //350 lines of code for drawing the graph //Here the offsetX will be used to move the graph } } </code></pre> <p>I am trying here to move a painted graph in a specific time to 1 "graph unit" to the left. So i use a timer which will change the offset in little steps, so it will be a smooth moving (thats the refreshRate for).</p> <p>At the first view this code worked, but later i found following problem: If i am using a refreshRate of 1 (1Hz) it will just fine move my graph in 1 step 1 (graph unit) to the left. If i am increasing the refreshRate my movement will slow done. At 20 FPS its slighly slow, at 200 FPS its really slow.. </p> <p>So here is what i tried:</p> <ol> <li><p>I used Refresh or Update instead of Invalidate</p></li> <li><p>I used a normal Thread (with Sleep) instead of the timer</p></li> </ol> <p>Both code changes didnt changed the result..</p> <p>Beside the movement with the timer I also can move the graph with my mouse and if the timer is running i can still smoothly move the graph with my mouse. So its not a peformance problem..</p> <p>I thought of a problem in the painting queue, because I am refreshing faster than the painting is done? (But why can I sill move the graph smoothly with my mouse?!)</p> <p>So i need a little help here. Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload