I have to check if a listbox's SelectedIndex is at the last index from a BackgroundWorker, but since I'm checking the listbox (which is on the GUI thread) from the BackgroundWorker I get this error:
System.InvalidOperationException: 'Cross-thread operation not valid: Control 'listBox1' accessed from a thread other than the thread it was created on.'
This is my code:
if (listBox1.SelectedIndex == listBox1.Items.Count)
{
//code here
}
How could I make this if statement work without being on the GUI thread?