SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

1
0

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

  • You must to post comments
1
0

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)

  • Any FrameworkElement derived class must be instantiated on, and manipulated from the UI thread
  • Any non-FE derived class may be instantiated on and manipulated from any thread
  • DependencyProperties (on DependencyObject) must be updated on a UI Thread
  • You may update Viewmodel bindings on a background thread because WPF automatically marshals bindings to dependency properties back onto the UI Thread

Best regards,
Andrew

  • Danny Ellenbogen
    Hi Andrew, Thanks for your quick response. I actually thought about this and early this morning replaced the timer with a .NET dispatcherTimer. That did the trick and for the past 3 hours the graph is plotting as expected. I will keep playing with the component, may try your suggestion using MVVM.Thanks, Danny
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.