Profile Picture

Repaint chart in separate thread

Posted By Ereona 12 Years Ago
Author
Message
Ereona
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 43, Visits: 1
I have a chart that I need to refresh very often (for example every second). I noticed that if I have a large value of MinorTickCount ScaleConfigurator's property and MinorGridStyle is visible, this refresh makes the whole application working slowly. If I break all processes I see that the main thread has the following call stack:

[Managed to Native Transition]
> System.Drawing.dll!System.Drawing.Graphics.DrawLine(System.Drawing.Pen pen, float x1, float y1, float x2, float y2) Line 1154 C#
Nevron.Presentation.dll!Nevron.GraphicsCore.lI1II1ll.PaintLine(float x1 = 112.0, float y1 = 9.0, float x2 = 112.0, float y2 = -70.0) + 0x4a bytes
Nevron.Chart.dll!Nevron.Chart.NBackWall.lI1llIIl1I(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}, Nevron.Chart.NAxis axis = {Nevron.Chart.NCartesianAxis}, Nevron.Chart.NGridLine l1ll111lIIl = {Nevron.Chart.NGridLine}) + 0x33b bytes
Nevron.Chart.dll!Nevron.Chart.NBackWall.lI1lI1ll1I(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}, Nevron.Chart.NAxis axis = {Nevron.Chart.NCartesianAxis}) + 0x28a bytes
Nevron.Chart.dll!Nevron.Chart.NBackWall.lI1llIIl11(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}) + 0xa9 bytes
Nevron.Chart.dll!Nevron.Chart.NCartesianChart.lI1llIlI1I(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}) + 0x1d4 bytes
Nevron.Chart.dll!Nevron.Chart.NChart.PreOrderPaint2D(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}) + 0x5a bytes
Nevron.Chart.dll!Nevron.Chart.NCartesianChart.PreOrderPaint2D(Nevron.Chart.NChartRenderingContext2D context = {Nevron.Chart.NChartRenderingContext2D}) + 0x5e bytes
Nevron.Chart.dll!Nevron.Chart.NContentPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0x17f bytes
Nevron.Chart.dll!Nevron.Chart.NPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0xdc bytes
Nevron.Chart.dll!Nevron.Chart.NContentPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0x1a4 bytes
Nevron.Chart.dll!Nevron.Chart.NPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0xdc bytes
Nevron.Chart.dll!Nevron.Chart.NContentPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0x1a4 bytes
Nevron.Chart.dll!Nevron.Chart.NRootPanel.RenderInternal(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}) + 0x9b bytes
Nevron.Chart.dll!Nevron.Chart.NDocument.Paint(Nevron.Chart.NChartRenderingContext context = {Nevron.Chart.NChartRenderingContext2D}, bool l1ll111l11I = false, bool recalc = true) + 0x11e bytes
Nevron.Chart.dll!Nevron.Chart.l1II11IlIl.PaintContent() + 0x3b bytes
Nevron.Presentation.dll!Nevron.GraphicsCore.NBitmapGdiRenderSurface.Paint(object sender = {Nevron.Chart.WinForm.NChartControl}, System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {System.Drawing.Rectangle}}, Nevron.GraphicsCore.l1ll11Il1 contentPainter = {Nevron.Chart.l1II11IlIl}) + 0x7c bytes
Nevron.Chart.dll!Nevron.Chart.WinForm.NControlView.Paint(object sender = {Nevron.Chart.WinForm.NChartControl}, System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {System.Drawing.Rectangle}}) + 0x12e bytes
Nevron.Chart.WinForm.dll!Nevron.Chart.WinForm.NChartControl.OnPaint(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {System.Drawing.Rectangle}}) + 0x3d bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e, short layer) Line 9541 + 0xf bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m) Line 13284 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13688 + 0xb bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 14109 + 0xe bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 14164 + 0xb bytes C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 15, System.IntPtr wparam, System.IntPtr lparam) Line 779 + 0xe bytes C#

I understand that painting with such settings needs a lot of time. My question: is it possible to repaint the chart in another thread? So the main thread would be free.
Related question: is it possible to find out if the rendering is in process? I could call refresh not every second but one second after the previous repainting was finished.

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Ereona,

You can use the image exported of the chart control in a separate thread:

nChartControl.ImageExporter.RenderToBitmap(someBitmap, false);

And then assign that bitmap to a image box in the main form. Note that the control itself is not thread safe so you need to synchronize access to it if it accessed concurrenly from different threads.

Hope this helps - let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team



Ereona
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)Forum Member (43 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 43, Visits: 1
Thank you but bitmap is not suitable in my situation because I have many interactivity events on the chart. I'll try to find another ways for optimization.



Similar Topics


Reading This Topic