Making datasets thread safe in C#
c#, dataset, multithreading
Solution
"Implement a wrapper layer with locks" is the way to go.
The wrapper layer will likely use locking that is specific to the way your application uses the DataSets.
Attempting to design a generic solution for a class as complex as a DataSet is probably doomed to failure.
For example, enumerating properties will generally not be thread-safe - so you would need to hold a lock for as long as any caller is enumerating any of the many collection properties (DataSet.Tables, DataTable.Rows, ...).
Problem
What's the best pattern for making datasets threadsafe on write? The best I can find by googling is 'implement a wrapper layer with locks' but at first blush this seems rather messy. Can someone recommend / point me in the direction of a good solution to this? It seems likely to be a problem that has already been solved somewhere. edit: I also need to bind the dataset to a ui grid, which complicates matters somewhat.