DataGridView DataTable(DataSet) and Thread safety

G

Guest

Hi,

I have a DataGridView, bounded to a DataTable which is populated/updated by
a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds
familiar to some of you ... I have posted a number of related questions
already.)

I want to have a worker thread starting to consume data from the DataTable.
Imagine that the DataTable contains a list of tasks. From the C# .NET
specification, DataTable "is safe for multithreaded read operations. You must
synchronize any write operations."

If the DataTable is managed programatically, e.g. not bound to a
DataGridView, the programming and testing shouldn't be too bad to create a
tread-safe application. However, my DataTable is bound to a DataGridView,
and I am concerned about the "random" updates made by the users. It's
probably wrong to assume any programatic/systematic behaviour by the users.

Is there a catch-all event between DataGridView and DataTable, such that I
can "lock" (or create a critical region) to control "Add", "Delete" and
"Update" to the DataTable? My worker thread will access the DataTable
directly, as programatic access to DataGridView is not allowed.

Or if anyone can advice me of any programming pattern for this type of set
up, I am all ears.

Thanks in advance.
 
L

Linda Liu [MSFT]

Hi George,

Thank you for posting.

I think when the BackgroundWorker is working, in order to prevent users
from adding, deleting or updating the data in the DataTable through the
DataGridView, you could disable the DataGridView.

You could set the Enabled property of the DataGridView to false before the
BackgroundWorker begins working and in the BackgroundWorker's
RunWorkerCompleted event handler set the DataGridView's Enabled property to
true.

Hope this helps.
If you have any other concerns, please don't hesitate to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top