There is a class IKS1A, it is working with a COM port through the SerialPort class. When receiving a certain number of bytes, the event SerialPort.DataRecived b is triggered. The IKS1A.DoUpdate method is called.
private void DoUpdate(object s, EventArgs e) { byte[] rx_buf = new byte[16]; SerialPort int_port = (SerialPort)s; int_port.Read(rx_buf, 0, 16); answer_measure_long answer; answer = BuffToStruct<answer_measure_long>(rx_buf); result_long_measure = answer.result; timeout = answer.timeout; UpdateST(); if (timeout <= 0 || result_long_measure<0) Port.DataReceived -= DoUpdate; } UpadateST- delegate class IKS1A. I thought to send through it to the form a message stating that the data was received and can be displayed.
UpdateST + = Update;
But when calling UpdateST, an exception is thrown; an attempt to call Form1 is not from the thread in which it was created.
Tell me how to properly transfer the data reception event in the IKS1A class to the form?