Same code,But WPF without binding is much slower than WF

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
lcuser
Posts: 5
Joined: Tue May 08, 2018 1:38 am

Same code,But WPF without binding is much slower than WF

Post by lcuser » Wed May 09, 2018 1:17 am

I use v8 SDK.
I cloned the sample code from https://github.com/ArctionLtd/LightningChartTutorials.I just check the SimpleLine_WF and SimpleLine_WPF_NB in LightningChart01 Directory.The two projects code behind are just the same except the reference is different.I made a little changes to them for making them a real-time chart with about 10,0000 points.Winform Version works great.But
1.WPF no binding verion is so slow.Both debug in vs or directly run exe are slow.
2.WPF no binding verion is blink a lot , making the chart blank and show frequently.
I don't know why.The two version code is the same.Please download the sample code from attachment.Thanks.
Attachments
LightningChartTutorials.7z
(7.7 KiB) Downloaded 511 times

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Same code,But WPF without binding is much slower than WF

Post by ArctionKestutis » Wed May 09, 2018 11:53 am

Thank you for interested in LightningChart.
The project you created is not exactly clones of the original one. You actually added Thread but using it incorrectly.

LightningChart updates must be done in UI thread. We don't guarantee operation otherwise. That is the way in WinForms and WPF, practically for all UI controls. All UI stuff must be updated in UI thread, otherwise the application is prone to crashing or doing all kind funny stuff.
Please use Invoke method of your parent form or control to execute the specified delegate synchronously on the main thread. Modification of Chart’s properties, data collection/calculation could be done in other Threads. However, Chart.EndUpdate() MUST be called in UI thread. At least the one that actually renders it (no other pending BeginUpdates). Otherwise the DirectX rendering itself can't work, and it will crash the chart or even the whole system. As you not using BeginUpdate-EndUpdate call, setting Series.Points property should done in GUI thread.

Our Demo App ‘real-time monitoring’ examples uses this pattern. Please check those as it should help to clarify the issue.

THERE IS EASY FIX for the problem in your example. Please set

Code: Select all

// ChartRenderOptions (in WPF) and RenderOptions (in WinForms)
chart.ChartRenderOptions.InvokeRenderingInUIThread = true;
This forces LightingChart to draw itself though Invoke().

Hope this helps.
All the best.

lcuser
Posts: 5
Joined: Tue May 08, 2018 1:38 am

Re: Same code,But WPF without binding is much slower than WF

Post by lcuser » Thu May 10, 2018 5:37 am

ArctionKestutis wrote:Thank you for interested in LightningChart.
The project you created is not exactly clones of the original one. You actually added Thread but using it incorrectly.

LightningChart updates must be done in UI thread. We don't guarantee operation otherwise. That is the way in WinForms and WPF, practically for all UI controls. All UI stuff must be updated in UI thread, otherwise the application is prone to crashing or doing all kind funny stuff.
Please use Invoke method of your parent form or control to execute the specified delegate synchronously on the main thread. Modification of Chart’s properties, data collection/calculation could be done in other Threads. However, Chart.EndUpdate() MUST be called in UI thread. At least the one that actually renders it (no other pending BeginUpdates). Otherwise the DirectX rendering itself can't work, and it will crash the chart or even the whole system. As you not using BeginUpdate-EndUpdate call, setting Series.Points property should done in GUI thread.

Our Demo App ‘real-time monitoring’ examples uses this pattern. Please check those as it should help to clarify the issue.

THERE IS EASY FIX for the problem in your example. Please set

Code: Select all

// ChartRenderOptions (in WPF) and RenderOptions (in WinForms)
chart.ChartRenderOptions.InvokeRenderingInUIThread = true;
This forces LightingChart to draw itself though Invoke().

Hope this helps.
All the best.
It works like a charm.Thank you so much.

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Same code,But WPF without binding is much slower than WF

Post by ArctionKestutis » Fri May 11, 2018 9:09 am

Enabled InvokeRenderingInUIThread property is not making Thread usage optimal, it just makes App thread-safe. As I wrote before, the usage of Invoke() method in correct places is the optimal solution.

Post Reply