I have an application that listens for a piece of hardware on a USB-Serial converter. My application must monitor several serial ports at the same time.
I will loop the serial ports I need to listen to and create a thread for each port. In the stream, I have a data processing procedure.
When I assign one port, it works flawlessly. When I listen to another, it also works. However, when I open both ports, the second port always throws UnauthorizedAccessException when calling serialPort.Open() . No matter in what order I open the ports, the second always fails.
I am listening to ports using serialPort.ReadLine() in a while loop.
Can .NET open multiple ports at the same time? Can i listen to both? Or should I use a different way (thread safe?) To access serial port events?
source share