I have a data table connected to a GridControl that I'm modifying within different threads, and the XtraGrid component seems to be catching the updates automatically and trying to refresh based on the data changes. However, sometimes the application crashes with an ArgumentOutOfRangeException. How to avoid this problem?
This issue is not connected with the Data Grid directly. Unfortunately, you can't change the grid's data source in a background thread since it will cause a lot of problems with synchronization. The Data Grid may perform some operations with the underlying data source at the same time as your background thread changes it. In this case the grid may receive a Change notification later and will try to update rows from the data source which will cause the mentioned problem. This problem may occur in a lot of cases. For example, when a user edits data, groups it or the Data Grid tries to recalculate the summaries. The only solution to this problem is to change the Grid's DataSource reference within a background thread (NOTE: You will need to implement it using the Invoke method). Said differently, within a background thread you should work with a local copy of the DataSource and pass its clone to the Grid's DataSource when necessary. In the attached example you will find a sample project which demonstrates this approach.
Is the XtraGrid thread safe?
Big red X: A control becomes crossed with red lines after an exception
Show all comments