I hate to start another thread on this, but I would like to know if this is viable or not. I have a readonly grid bound to a DataSet containing one or more DataTables. If I periodically launch a BackgroundWorker that returns a new DataTable with matching schema, can I update the the grids bound DataSet via DataSet.Merge(returned DataSet)?
This technique is locking up our UI thread in some instances as soon as the BackgroundWorker starts, but I cannot figure out why. I am only passing strings into the RunWorkerAsync() function, creating all local objects in the DoWork() function, and returning a new DataSet back to the UI thread via the RunWorkerCompleted Result argument. I am not updating the grid datasource at all until the RunWorkerCompleted event.
It seems that if I mouseover certain parts of the grid or activate new rows while the BackgroundWorker is running, the UI freezes. Am I missing something in my code, or is this pattern simply not supported?
Hi Ron,
It's hard to say for sue without seeing the code in action. Does your background worker thread still have a reference to the DataSet after it returns it?
I can't say I'm that familiar with RunWorkerCompleted. If you check grid.InvokeRequired inside of that event, does it return true? If so, then you need to marshal the DataSet back to the UI thread, in which case, the UI thread could be locked for a long time if the DataSet is fairly large.
Hey Mike -
I have reproduced my issue with out of the box DataGridViews, so this does not appear to be an Infragistics problem.
To answer your questions (or add to the confusion?) - the RunWorkerCompleted event of the BackgroundWorker component gets fired on the UI thread (as I understand it), so it should be safe to update the grid datasource from there. I have since discovered that my issue is with simultaneous OleDbDataAdapter.Fill calls. Picture a form with 2 grids, top and bottom. By itself, my long running .Fill call on the BackgroundWorker thread works great. The UI remains responsive and the data in the top grid is refreshed when it completes. However, each row that I select in the top grid issues another (separate) OleDbDataAdapter.Fill call to populate the bottom grid. As soon as that second .Fill call is made, the UI becomes unresponsive until the BackgroundWorker completes.
My current understanding is that those two .Fill calls should be operating on separate threads, so I am not clear on why they are conflicting with each other.
I appreciate all your work here on the forums. Thanks.