How exactly does the SuspendUpdates work? I was under the impression that the surface the ViewportManager is attached to should not be redrawn until the IUpdateSuspender was disposed.
using (var s = ViewportManager.SuspendUpdates())
{
// Clear ObservableCollection<IChartSeriesViewModel> that is databound to SciChartSurface.SeriesSource
// Add new IChartSeriesViewModel to ObservableCollection
}
The behavior I’m observing is after the clear it is blanking out the chart and then I see the new series drawn on the surface. I was expecting to see the chart immediately switch to the new series without first seeing the chart surface being cleared. Is this not the behavior of SuspendUpdates?
- dkuo asked 10 years ago
- You must login to post comments
Hi there,
This is a good question. Our ISuspendable documentation says
/// <summary>
/// Suspends drawing updates on the target until the returned object is disposed, when a final draw call will be issued
/// </summary>
/// <returns>The disposable Update Suspender</returns>
IUpdateSuspender SuspendUpdates();
However, we have actually used ISuspendable throughout SciChart as a nice, clean thread-safe pattern to pause/resume operations on many elements. So it actually has subtle differences for different elements.
Here is a quick summary / run-down of what ISuspendable does on different elements:
- Annotations: When suspended, prevents positioning of the annotation
- ViewportManager: When suspended, prevents re-calculating YAxis, XAxis ranges
- SciChartSurface: When suspended, prevents re-drawing of the chart.
- DataSeries: When suspended, locks the ParentSurface.SyncRoot, preventing re-draw on the chart. Also prevents concurrent updates from causing threading issues.
- Axis: When suspended, prevents drawing of axis labels and ticks
That’s pretty much all the classes that implement ISuspendable. If you are wanting to freeze the chart from inside a view model, I would recommend one of two strategies:
-
You can call DataSeries.SuspendUpdates(), which will lock the parent surface, only if the data series is attached. There are known issues if a DataSeries is a child of more than one SciChartSurface.
-
You can inject your SciChartSurface as ISuspendable into your view model and control it directly.
-
If (2) is upsetting, as it breaks MVVM, you can create an attached behaviour which controls SciChartSurface.SuspendUpdates via a boolean property. I would not personally recommend this approach as it can result in threading issues. One of the beauties of ISuspendable.SuspendUpdates() is it is truly nested, and thread-safe.
-
Another option is to lock SciChartSurface.SyncRoot directly. This should only be used for short operations but can be used to freeze the render thread temporarily
I hope this clarifies the Api and when / where you should suspend chart drawing!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- last edited 9 years ago
- You must login to post comments
Please login first to submit.