In my custom control am using nearly 1000 series with 100 points each which results in delay in drawing and even after drawn also it takes some amount time to be responsive.
Am even using Begin and End update before loading points. But no use.
I have replicated the same in a simple sample by drawing a line in a loop, which also goes to unresponsive state.
Is there any solution to overcome this.
public Form2()
{
InitializeComponent();
ControlExt controlExt = new ControlExt();
this.Controls.Add(controlExt);
}
public class ControlExt : Control
{
public ControlExt()
{
Height = 500;
Width = 1000;
}
protected override void OnPaint(PaintEventArgs e)
{
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 100; j++)
{
using (var pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawLine(pen, 400, 200, 300, 100);
}
}
}
}
}
Drawing lines is done on the main thread, and can be quite inefficient when there is many lines. Winforms is based on GDI, and this uses Immediate Mode rendering. This has a tendency to scale poorly since the processor have to send all the commands to the graphics device each frame.
The typical solution is to use fewer drawing commands, and therefore suffer less overhead. For example: