Home>

Windows 10 Home 64bit,
Visual Studio 2017 Community Edition,
Developed with .NET Framework 4.6, WPF + C #.

I want to create a graph control with WPF,
As a test, we created a control that draws 3,000 points as shown below.

namespace GraphTest
{
    using System;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Media;
    public class GraphControl: FrameworkElement
    {
        private SolidColorBrush _brush;
        private Pen _pen;
        private Random _rand;
        public GraphControl ()
        {
            this._brush = new SolidColorBrush (Colors.Orange);
            this._brush.Freeze ();
            this._pen = new Pen (this._brush, 1.0);
            this._pen.Freeze ();
            this._rand = new Random ();
        }
        protected override void OnRender (DrawingContext drawingContext)
        {
            for (var i = 0;i<3000;i ++)
            {
                drawingContext.DrawEllipse (this._brush, this._pen, new Point ((double) this._rand.Next (0, (int) this.RenderSize.Width), (double) this._rand.Next (0, (int) this.RenderSize.Height)), 3.0, 3.0);
            }
            Task.Run (async () =>
            {
                await Task.Delay (1);
                await Dispatcher.BeginInvoke ((Action) this.InvalidateVisual);
            });
        }
    }
}

Since InvalidRate () is called asynchronously at the end of OnRender (),
It continues to draw all the time.

At this time,
When checking the process memory with the Visual Studio diagnostic tool,
It turns out that GC is performed very frequently.
And probably because of this, the drawing speed was quite slow.

I'm not going to do anything strange in OnRender (),
I think the cause of GC is in DrawingContext.DrawEllipse ().
In other words, this drawing method recognizes that there is a limit in the first place.

But there are SciChart, etc.
Some have achieved very fast drawing.
How are these things implemented?