I have a form that has a master and detail tables on it. As you page through the master table, I want to populate the detail table on a background worker.
So I have the background worker _DoWork fill a data reader object and then the _RunWorkerCompleted update the datagrid with the populated data reader.
This works fine so long as the background worker has completed before you go to the next master record.
I started using a timer where the detail records were not populated unless you rested on one master record for more than 0.1 seconds... Which worked great performance wise -- so if the user is scanning through records, why incur the sql overhead of doing queries for the detail records that will never be viewed... But that didn't fix the problem of the background worker already existing.
So next I tried destroying the background worker if it wasn't complete and recreating it. That worked except when you cycled really quickly between records. So next I tried close the data reader, then destroying the background worker, the data reader, and then forcing garbage collection. Even that didn't work --- .NET throws an error of "There is already an open DataReader associated with this Command which must be closed first." --- in the debugger the DataReader in question shows to be closed.
So my question is: How do I accomplish what I want to do? How can I have slowly queried detail records that can be ignored or discarded (without slowing down the UI) when they are no longer relevant since the master record moved?
Start Free Trial