SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Hello,
I am now experimenting with SciChart (trail period).
I want to constantly draw the latest 300 points of a real time generated sine wave. I wrote a little program that tries to do this (attached). The sine wave is generated in the OnTimer function. I expected Draw_Limited_Range() function to draw the latest 300 points using XAxis.VisibleRange. Unfortunately this doesn’t work from OnTimer. Same function does work as expected when called from a button (Set VisableRange).
The output window of the debugger keeps displaying following message: A first chance exception of type ‘System.InvalidOperationException’ occurred in WindowsBase.dll
I tried this both on Ver 3.2 and 3.1; On 3.1 it crashes very fast.
What am I doing wrong?
Thanks,
Danny
Hi Danny,
Without being able to debug the code, we can’t tell I’m afraid. However it sounds to me like you have a cross-thread issue.
SciChart itself is a very thread-safe user control. Most WPF UserControls can only ever be accessed from the UI thread. With SciChart, you can append or modify data (DataSeries API) on a background thread. You can control certain pairs of the API from background threads.
Unfortunately, VisibleRange is a DependencyProperty and WPF requires that DP’s are set from the UI Thread.
We work around this in our examples by using MVVM. In MVVM, data bindings can be updated in ViewModels from the background thread and WPF will automatically marshal the binding to the UI Thread.
The rule of thumb is (and this is a WPF restriction, not a SciChart one)
Best regards,
Andrew
Please login first to submit.