I'm using SharpAdbClient and I register an event called OnDeviceConnected
which fires when a device is plugged in to the PC where my form is running on.
When a device is connected and this event is fired, I'm trying to set a PictureBox image like so:
void OnDeviceConnected(object sender, DeviceDataEventArgs e)
{
...
imgBootFlashState.Image = Properties.Resources.locked; // CRASHES
helpBootState.Image = Properties.Resources.help_boot_flash_disabled; // CRASHES
...
}
This attempt throws this error:
Cross-thread operation not valid: Control 'MainForm' accessed from a thread
other than the thread it was created on.
I have no idea where this "other" thread came from, since it didn't came from me, BUT If I'm changing the PictureBox's BackgroundImage
like so:
void OnDeviceConnected(object sender, DeviceDataEventArgs e)
{
...
imgBootFlashState.BackgroundImage = Properties.Resources.locked; // WORKS
helpBootState.BackgroundImage = Properties.Resources.help_boot_flash_disabled; // WORKS
...
}
It works fine.
How can it be? What is the deal with this error?
I know I can just solve it by using the BackgroundImage
property, but I want to understand what throws this error...?