I have a WinForms app (c#) that has a background thread that periodically grabs data from a data source, does some manipulation of it, and puts it in a DataTable. There are 1 or more components in the app that periodically poll this common data to do stuff with it. I'm wondering, what's the "right" way to synchronize this, so e.g. the components don't query the data while it's being updated?
Locking on something while the data is being updated won't work because the updating could take several seconds. So I thought, why not "double-buffer" it, e.g. update the data in a second DataTable, then when finished swap (locking just for the swap operation). Is this appropriate, or is there a better way to do this?