Winforms Frameratelock in OnPaint?
I'm currently trying to polish my application and improve it's
performance. Basically, it's an advanced Graph- class. It draws a few
lines and refreshes them.
After fixing a few slow points, I wanted to benchmark my result. My
drawing was stuck at ~65 FPS (which is perfect but I'm benchmarking). I
Invalidate my object in a timer (set to 1 ms) and redraw my stuff using
the protected override void OnPaint -"way".
After that, I put the Invalidate() into the protected override void
OnPaint. The FPS was set to a few thousand afterwards. But using that
method will result in an empty screen.
My question is: Is that issue done on purpose? That would make sense as
anything higher than your screen refreshrate is wasted power. But I'd like
to disable that "lock" for my benchmarking.
Sample code:
//Timer to refresh
private void timer1_Tick(object sender, EventArgs e)
{
Invalidate();
}
private DateTime date = DateTime.UtcNow;
private long times = 0;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//Drawing
e.Graphics.DrawLine(new Pen(Brushes.Black), 50, 50, Width - 100,
Height - 100);
//Required to tell me the framerate
if ((DateTime.UtcNow - date).Seconds > 1)
{
date = DateTime.UtcNow;
Debug.WriteLine(times);
times = 0;
}
times++;
}
Thanks
~Steve
No comments:
Post a Comment