The information in section applies to both ChartDataSeries and any of the various IndicatorSeries mentioned above.
In order for the API to be able to safely update data in real-time and yet still allow access to the same data, a locking strategy is employed to prevent data corruption and various other concurrency errors.
If you mind two rules of thumb, this will never be issue.
- If your code is running within, or called from any of the API event handler methods (ChartDataSeries.DataLoadComplete, ChartDataSeries.DataSeriesUpdated, IndicatorSeries.IndicatorSeriesUpdated), then no locking necessary because the API wraps these event calls within a lock already.
- If your code is running outside any of the above mentioned event handlers and you to access the chart or indicator data, you must wrap the data access with Lock() and Unlock() methods (either on the ChartDataSeries or the IndicatorSeries).
This locking strategy is similar in anture to the rest of the way the T4 API operates and should not be unfamiliar.
It is worth mentioning that code that executes while the API data structures are locked must run quickly and efficiently. The API must queue real-time during the time the data structures are locked, and queuing for too long could result in delayed updates and in extreme cases, excessive memory use.