If I use the following code (paraphrased a bit), which draws a large triangle on the screen. It rotates the triangle every frame and displays the frame rate as well:
Thread drawLoop = new Thread(new ThreadStart(Draw));drawLoop.Start()...void Draw(){ for(;;) { graphics.Clear(); graphics.Draw(); this.Invalidate(); Thread.Sleep(16); // has to be integer value, 16ms = 62.5fps }}
It show's a very solid 66.7FPS on the screen and the animation is very smooth.
However, when I tried to implement this as a timer and EventHandler, e.g. :
var timer = new System.Timers.Timer(1000.0f / 60.0f); //use 60FPS (also tried 16ms as before)timer.Elapsed += new ElapsedEventHandler(Draw);timer.Start()void Draw(object source, ElapsedEventArgs e){ graphics.Clear(); graphics.Draw(); this.Invalidate();}
Besides System.Timers.Timer, I've also used System.Windows.Forms.Timer and System.Threading.Timer and they all yield identical results; slow and jerky animation with frame rates that jump around +/- 50% and are otherwise lower than they should be (e.g. 16ms should be ~62FPS but you get closer to 40FPS).
This is extremely frustrating and I hope someone here has an answer as to what I should do.