I have a form that contains a BindingSource and a BackGroundWorker. While navigating records, on the BindingSource.PositionChanged event, I run the BackGroundWorker to pull data from a different datasource, which is then input into textboxes as suggested data (not bound, the user can modify this data as they need to).
The problem I encounter is, if I navigate through the records before the BackGroundWorker has finished, it obviously throws an exception. So I suppose that I need to either wait for BackGroundWorker Completed event before navigating to the next record or cancel the work it is currently doing. For right now I put in:
The accountNumberTextBox changes with each record navigation, but obviously if the BackGroundWorker is already busy, I somehow need to know that I need to cancel the worker immediately and start the async operation all over again. I also need to make sure that the previous records data isnt being filled into current records unbound textboxes. How should I work to verify the account number data being returned from the worker is the same as the account number that called the worker? As well, how should I handle the worker being busy/cancellation in this scenario?
The problem I encounter is, if I navigate through the records before the BackGroundWorker has finished, it obviously throws an exception. So I suppose that I need to either wait for BackGroundWorker Completed event before navigating to the next record or cancel the work it is currently doing. For right now I put in:
Code:
If Not BackGroundWorker.IsBusy Then BackGroundWorker.RunWorkerAsync(AccountNumberTextBox.Text)