SciChart Android 2D Charts API > Advanced 2D Charting Topics > Suspending Updates of Chart
Suspending Updates of Chart

When performing multiple updates, such as VisibleRange changes, DataSeries changes and RenderableSeries or Axis property changes, each change can potentially trigger a redraw in SciChart. To prevent this and combine several updates into one, use the methods from the ISuspendable implementation on SciChartSurface or use UpdateSuspender.using() helper method which accepts ISuspendable which should be suspended and Runnable which should be executed while ISuspendable is suspended.

Using UpdateSuspender API
Copy Code
// use try-with-resources statement
try(IUpdateSuspender suspender = surface.suspendUpdates()){
    dataSeries.append(x1, y1);
    dataSeries.append(x2, y2);
    dataSeries.append(x3, y4);
    Collections.addAll(surface.getXAxes(), xAxis);
    Collections.addAll(surface.getYAxes(), yAxis);
    Collections.addAll(surface.getRenderableSeries(), rSeries);
} catch (Exception e){

}

or use UpdateSuspender.using() which does the same thing
UpdateSuspender.using(surface, new Runnable() {
    @Override
    public void run() {
        dataSeries.append(x1, y1);
        dataSeries.append(x2, y2);
        dataSeries.append(x3, y4);
        Collections.addAll(surface.getXAxes(), xAxis);
        Collections.addAll(surface.getYAxes(), yAxis);
        Collections.addAll(surface.getRenderableSeries(), rSeries);
    }
});

Using UpdateSuspender API to avoid problems because of multithreading

By default SciChartSurface can be used with different IRenderSurface implementations. Some of them create a separate Java Thread for rendering (e.g. RenderSurfaceGL and GLTextureView). This means that chart can be updated from one Thread ( usually from UI Thread ) and rendered on other thread. Potentially this could lead to different problems ( race conditions, deadlocks etc ) when different Threads try to get access to some shared resource ( in our case SciChartSurface or its part ). In this case UpdateSuspender API which allows to avoid these kind of problems by telling SciChartSurface or its part that you want to update it.