I have a program based on Windows Form Application in C#. I need to read data from Serial Port(Com Port). For this purpose, I need to use Threads and Serial Ports in C#. My program follows the following sequence.
- First it initializes the thread which is the Foreground thread.
- It will check that the serial port is open or not and then start reading the program.
All of the programs are working fine but After clicking on the close button I got this error at this line 'string machine_data = serialPort1.ReadTo("\u0003");'
Here is the Snapshot of my error:
I also tried this method to close Thread. And I also used this method to Terminate Threads in close function.