I’m storing DataTable in ASP .NET Cache property. Operations that can be done on that DataTable are:
- binding to grid control (that 3rd party grid internally manages datasource object, after postback its DataSource is NULL, I assume once data is binded it does not use datasource DataTable any more)
- removing rows from DataTable (Row.Delete()
I added basic reader/writer locks when explicitly working on that DataTable instance, but I wonder are there any other thread safety issues with that solution. I guess something might go wrong when grid control is in the middle of DataBinding, and other thread removes rows? If so, how can I sync access to that table so that no Delete method calls are made when grid control is binding? Are there any combination of events where I can put AcquireWriterLock & ReleaseWriterLock methods ?
Thanks,Pawel
If you are exposing the datatable via data-binding, then forget it; you cannot make that thread-safe. Even if you wrap the
DataViewsomehow (in a customITypedList), that doesn’t do enough – data-binding makes assumptions about the data, in particular theIListetc – for example, that it isn’t going to randomly change length in a thread-contended way in the middle of iterating the data or adding a row on the UI thread.There is provision for changes on the same thread via events … but not cross-threaded.