I've got a background worker on a form and I've written some long running DB interaction in it.
When I click a button on my form, the following runs:
if (!bwFind.IsBusy)
bwFind.RunWorkerAsync(param);
Where bwFind is the BackgroundWorker and param is a DevExpress CriteriaOperator.
I update a progressbar in the Progress_Changed event handler.
And I do the following in the RunWorkerCompleted event handler:
dataGrid.DataSource = this.dataObject;
dataGrid.Refresh();
label1.Text = this.dataObject.Count.ToString(); // problem appears here
Problem is, that I get a Null Ref Exception at the line noted, however I instantiate that object, at the end of the DoWork method.
I know that DoWork isn't running, cause if I do a null-check before using it, press the button on the form a second time... it runs, and all works as expected.
Maybe I'm not using the BackgroundWorker correctly, but this happens very often whenever I use the component.