First, I am not creating any new threads via invoke or any other intentional
means. As far as I know, there is just one thread, which is the main
thread.
My windows form class creates a new DeviceController() object which
initializes a serial port and defines a serial port event handler, which
processes the raw data from the serial port and then generates my custom
event (OnNewData).
public partial class LoggerForm : Form
{
DeviceController myDevice;
public LoggerForm()
{
InitializeComponent();
myDevice = new DeviceController();
myDevice.OnNewData += new
DeviceController.DeviceDataDelegate(DeviceDataEven tHandler);
}
void DeviceDataEventHandler(object sender, DeviceDataEventArgs e)
{
logTextBox.Text = e.DeviceData;
}
The consumer for my custom event is DeviceDataEventHandler(), which fires as
it should but produces the following run-time error: "Cross-thread operation
not valid: Control 'logTextBox' accessed from a thread other than the thread
it was created on."
How could this be? I thought an event was run on the same thread that
created it. It almost seems like the event is handled on a new thread.
Any ideas on why this is happening?
Thanks in advance.
Erik