You know, I swear before you edited your code, you haddeclared at Form level, outside the BGW's DoWork event handler.Code:Dim ItemSelection = ListBox1.SelectedItem
Of course it will give problems referencing the ListBox inside the DoWork event handler, as that runs on a thread that is not the UI's thread and so you can't access any Form's Controls in there.
In any case, I prefer Ian's solution of passing the value as an argument rather than accessing a (disappeared) global variable![]()




Reply With Quote