I have a thread in a function which start the live monitoring, it basically, opens the serial port and continously reading data from serial port. However, If I need to terminate this thread, how should I do it? Because If I don’t terminate the running thread which opened the specific serial port and reading data. When I close it and call the function again. The same serial port cannot opened. I suspect that the serial port is not closed properly and is still running in a seperate thread. So I think i have to terminate that thread in order to open the same serial port again next time. Does anyone have any idea of how to achieve this?
I have seen some forum said that Thread.Abort() is dangerous to use. It should only be used in last resort.
Thanks for any helps.
Charles
Generally, you design the method that is run in the background thread to listen for cancellation requests. This can be as simple as a boolean value: